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); } }

17th May 2022, 5:50 AM
Karuchiu Wamahiga
Karuchiu Wamahiga - avatar
2 Réponses
+ 2
Figured out why. The for loop test-expression should be i >=0; instead of i <= 0;
17th May 2022, 6:18 AM
Karuchiu Wamahiga
Karuchiu Wamahiga - avatar
+ 1
Try using the search bar This Question is asked frequently https://www.sololearn.com/Discuss/3016540/?ref=app
17th May 2022, 6:01 AM
Chris Coder
Chris Coder - avatar
Aujourd'hui en vedette
.
1 Votes
What?
0 Votes
HTML
0 Votes
Quiz duel
0 Votes
Web
0 Votes
FRC Coding?
1 Votes
help
0 Votes
AI
2 Votes