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++; } } }
3 Réponses
+ 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]);
}
}
}
+ 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]);
}
...
+ 2
You will need a loop and count the index from the end of this array to its beginning.