File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments