0
Can any one please tell me how to print backwards of it like. R E T U P M O C
3 Antworten
+ 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 :)