+ 1

How to solve reverse String lesson in java...?

27th Mar 2021, 9:07 AM
Aqeel Khan
Aqeel Khan - avatar
7 Answers
- 3
I could, but then what would you learn? You should try to code it yourself. If you have trouble after trying and reviewing the course, then save your code to the playground and post a link to your code and explain the issue(s) that you're having, what you've tried etc. Then we will help you with your issues.
27th Mar 2021, 9:41 AM
ChaoticDawg
ChaoticDawg - avatar
+ 6
Loop over the string from back to front outputting each char with the print method instead of println.
27th Mar 2021, 9:29 AM
ChaoticDawg
ChaoticDawg - avatar
+ 4
String rev = ""; for (char i : arr) rev = i + rev; System.out.println(rev);
5th Jun 2021, 7:08 AM
Suraj Kumar
Suraj Kumar - avatar
+ 3
Ok i am trying
27th Mar 2021, 9:42 AM
Aqeel Khan
Aqeel Khan - avatar
+ 1
here is an examle of code: 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(); for(int i=arr.length-1;i>=0;i--){ System.out.print(arr[i]); } //your code goes here } }
29th Sep 2021, 2:05 PM
Hasnae BOUHMADY
Hasnae BOUHMADY - avatar
0
Can u write it ...?😊
27th Mar 2021, 9:33 AM
Aqeel Khan
Aqeel Khan - avatar
0
Using for-each for simplicity. 4 lines of code added. https://code.sololearn.com/cig6PA96rplT/?ref=app Your original code has splitted the String into an Char[] array. For-each loop loops through the Char[] array, one Char (i) at a time, from left-to-right order. String rev is the temporary result. "rev = i + rev" means you are adding the i to the front, reversing the String.
6th Jun 2021, 3:39 AM
Lam Wei Li
Lam Wei Li - avatar