+ 2
How to reverse a string in java
8 Respostas
+ 9
Godfred Opintan ,
since this question has been asked frequently, please use the search bar.
thanks!
+ 5
use array- https://code.sololearn.com/cy26M72V2D2g/?ref=app
StringBuilder
https://code.sololearn.com/cpAv2CZejx67/?ref=app
+ 2
Thanks
+ 2
Reverse it by decreasing .length()-1 function in the loop
+ 1
You can also do it this way without StringBuilder.....
https://code.sololearn.com/cOF9nbaxaytB/?ref=app
+ 1
That's short. thanks
+ 1
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String text = scanner.nextLine();
char[] arr = text.toCharArray();
for(int i=arr.length-1;i>=0;i--)
{
System.out.println(arr[i]);
}
}
}
0
for(int i = arr.length - 1; i >= 0; i--){
System.out.print(arr[i]);
yup, my issue, why it didn´t work. Was separating by comma and not semi colon in the for condition. " , } ) " these three are really a pain in the ass sometimes, lol