Skip to content

Commit 1c05a44

Browse files
authored
reverse A String in java
1 parent b7b5da0 commit 1c05a44

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/reverseAString.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// java program to reverse a word
2+
3+
import java.io.*;
4+
import java.util.Scanner;
5+
6+
class GFG {
7+
public static void main (String[] args) {
8+
9+
String str= "Geeks", nstr="";
10+
char ch;
11+
12+
System.out.print("Original word: ");
13+
System.out.println("Geeks"); //Example word
14+
15+
for (int i=0; i<str.length(); i++)
16+
{
17+
ch= str.charAt(i); //extracts each character
18+
nstr= ch+nstr; //adds each character in front of the existing string
19+
}
20+
System.out.println("Reversed word: "+ nstr);
21+
}
22+
}
23+
24+
//Contributed by Tiyasa

0 commit comments

Comments
 (0)