Reverse string java
![]() |
reverse string java |
Write a recursive function that, given a string s= “OOP is Fun”, print the characters of s in reverse order
public class StrReverse {
public static void main(String args[])
{
String s = "OOPs is fun";
byte[] s_reverse = s.getBytes();
byte[] res = new byte[s_reverse.length];
for (int i = 0; i < s_reverse.length; i++)
{
res[i] = s_reverse[s_reverse.length - i - 1];
}
System.out.println(new String(res));
}
}