0
Program to reverse a String.However, I receive no output and there are no build errors. What am I doing wrong?
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(); //reversing a String String revText = ""; for(int i = (arr.length -1); i <= 0; i--){ revText += arr[i]; } System.out.println(revText); } }
2 Respostas
+ 2
Figured out why.
The for loop test-expression should be i >=0; instead of i <= 0;
+ 1
Try using the search bar
This Question is asked frequently
https://www.sololearn.com/Discuss/3016540/?ref=app