Skip to content

Commit 5a5ddbd

Browse files
authored
Added the reverse a string program
1 parent d4f6b3d commit 5a5ddbd

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

reverse.java

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

0 commit comments

Comments
 (0)