+ 5
How can someone reverse String without recursion?
4 Antworten
+ 9
You can do this:
String str = "MyString";
String reverse = "";
for(int i = str.length() - 1; i >= 0; i--){
//print:
System.out.print(str.charAt(i);
//or if you need a new String:
reverse += "" + str.charAt(i);
}
+ 6
In python, you can reverse a string with just one line of code:
str = "reverse"
str = str[::-1]
print(str)
/*output is "esrever"*/
+ 2
you can use for loop or while loop to do that
+ 2
Easiest way to print reverse string :)
name = "nraeLoloS"
print(name[::-1])