I have \"Hello World\"
kept in a String variable named hi
.
I need to print it, but reversed.
How can I do this? I understand there
We can use split() to split the string .Then use reverse loop and add the characters.
class test
{
public static void main(String args[])
{
String str = "world";
String[] split= str.split("");
String revers = "";
for (int i = split.length-1; i>=0; i--)
{
revers += split[i];
}
System.out.printf("%s", revers);
}
}
//output : dlrow