We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f4915d6 commit dc23b75Copy full SHA for dc23b75
ReverseString.java
@@ -0,0 +1,26 @@
1
+import java.util.Scanner;
2
+
3
+public class ReverseString {
4
+ // Method to reverse a string without built-in functions
5
+ public static String reverse(String input) {
6
+ String reversed = "";
7
+ for (int i = input.length() - 1; i >= 0; i--) {
8
+ reversed += input.charAt(i); // Append characters in reverse order
9
+ }
10
+ return reversed;
11
12
13
+ public static void main(String[] args) {
14
+ Scanner input = new Scanner(System.in);
15
16
+ // Taking user input
17
+ System.out.print("Enter a string: ");
18
+ String userInput = input.nextLine();
19
20
+ // Calling the reverse method
21
+ String reversedString = reverse(userInput);
22
23
+ // Displaying the result
24
+ System.out.println("Reversed String: " + reversedString);
25
26
+}
0 commit comments