Skip to content

Commit 8777f00

Browse files
Merge pull request seeditsolution#312 from pbikash/patch-1
reverse string
2 parents e35fc16 + 1d01701 commit 8777f00

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

reverse string

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.lang.*;
2+
import java.io.*;
3+
import java.util.*;
4+
5+
// Class of ReverseString
6+
class ReverseString {
7+
public static void main(String[] args)
8+
{
9+
String input = "GeeksforGeeks";
10+
11+
// getBytes() method to convert string
12+
// into bytes[].
13+
byte[] strAsByteArray = input.getBytes();
14+
15+
byte[] result = new byte[strAsByteArray.length];
16+
17+
// Store result in reverse order into the
18+
// result byte[]
19+
for (int i = 0; i < strAsByteArray.length; i++)
20+
result[i] = strAsByteArray[strAsByteArray.length - i - 1];
21+
22+
System.out.println(new String(result));
23+
}
24+
}

0 commit comments

Comments
 (0)