Skip to content

Commit 951498d

Browse files
Merge pull request #206 from Mohit5700/patch-1
Java program to reverse a string
2 parents 34c9689 + f979101 commit 951498d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

reversing a string

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java.util.*;
2+
class ReverseString
3+
{
4+
public static void main(String args[])
5+
{
6+
String original, reverse = "";
7+
Scanner in = new Scanner(System.in);
8+
9+
System.out.println("Enter a string to reverse");
10+
original = in.nextLine();
11+
12+
int length = original.length();
13+
14+
for (int i = length - 1 ; i >= 0 ; i--)
15+
reverse = reverse + original.charAt(i);
16+
17+
System.out.println("Reverse of the string: " + reverse);
18+
}
19+
}

0 commit comments

Comments
 (0)