+ 1

Write a javaprogram to take input as string and result reverse of it

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 s=""; for(int i=arr.length-1;i<arr.length ;i--){ s=arr[i] + s; } //your code goes here System.out.println(s); } } Can anyone help me to correct my code!!!

16th Apr 2021, 2:46 PM
Keerthi goli
Keerthi goli - avatar
3 Réponses
+ 3
for(int i=arr.length-1;i>=0;i--){ s=s+arr[i]; }
16th Apr 2021, 3:17 PM
JaScript
JaScript - avatar
+ 2
Thank you
16th Apr 2021, 3:27 PM
Keerthi goli
Keerthi goli - avatar