- 2

How to reverse a string in java ?

16th Mar 2022, 4:59 PM
Shai Shab
Shai Shab - avatar
2 Réponses
16th Mar 2022, 5:01 PM
Adil
Adil - avatar
0
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(); String res =""; for (int x=arr.length-1;x>=0;x--){ res+=arr[x]; }System.out.println(res); } }
16th Mar 2022, 5:01 PM
Shai Shab
Shai Shab - avatar