Can any one please tell me how to print backwards of it like. R E T U P M O C | Sololearn: Learn to code for FREE!

0

Can any one please tell me how to print backwards of it like. R E T U P M O C

https://code.sololearn.com/c5u2gNgw5EK2/?ref=app

4/24/2022 9:09:25 AM

ALI IMRAN

3 Answers

New Answer

+3

You are almost there. Just start at a-1, reverse the terminating condition and count down not up. If you do not want the line break, then use print in lieu of println. for(int i = a-1 ; i >= 0 ; i--) { System.out.print(str1.charAt(i)); } I would also like to point your attention towards the StringBuilder class which has a reverse method. Ideal to use in a method that returns a reverse string instead of printing it. Makes your code more flexible and reusable.

+3

Thanks Ani.💯

+3

You're welcome :)