diff --git a/Interview Questions/reversing-a-string.java b/Interview Questions/reversing-a-string.java new file mode 100644 index 0000000..2105138 --- /dev/null +++ b/Interview Questions/reversing-a-string.java @@ -0,0 +1,21 @@ +import java.util.*; +class ReverseString +{ + public static void main(String args[]) + { + String originalString, reverseString = ""; + Scanner input = new Scanner(System.in); + + System.out.print("Enter a string to reverse : "); + originalString = input.nextLine(); + + int length = originalString.length(); + + for (int i = length - 1 ; i >= 0 ; i--){ + reverseString = reverseString + originalString.charAt(i); + + } + + System.out.println("Reverse of the string: " + reverseString); + } +} \ No newline at end of file