0

How to print Reverse string

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(); //your code goes here for(i=0;i<arr.length;--i){ arr[¡] = arr[arr.length-1]; i++; } } }

25th Aug 2021, 10:29 AM
Nipun
Nipun - avatar
3 ответов
+ 2
Its done 🤗🤗🤗 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(); //your code goes here for(int i=arr.length-1;i>=0;i--){ System.out.println(arr[i]); } } }
25th Aug 2021, 11:42 AM
Nipun
Nipun - avatar
+ 5
Nipun , it is much easier as you expect: (reworked the loop header, removed 2 lines of code, and added an output) .... for(int i = arr.length-1; i >= 0; i--){ System.out.print(arr[i]); } ...
25th Aug 2021, 10:52 AM
Lothar
Lothar - avatar
+ 2
You will need a loop and count the index from the end of this array to its beginning.
25th Aug 2021, 10:52 AM
JaScript
JaScript - avatar