0
Unable to find error! In reverse string program.
5 Answers
+ 1
https://code.sololearn.com/ch2EV908N5mU/?ref=app
here
you didnt put -1, so its out of bounds
+ 1
You are getting an index out of range because you directly used the length of your table as an index.
The length of "asd" is 3, however, the indexes starts at 0, meaning that the max index is 2!
You can fix it by adding a -1 in there:
System.out.print(arr[Ttl-1]);
0
Thank You idk and Apollo-Roboto
- 1
yep, its like python and c++
- 1
Here's the corrected code:
import java.util.Scanner;
public class Program {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char a[] = sc.nextLine().toCharArray();
for (int i=a.length-1;i>=0;i--) {
System.out.print(a[i]);
}
}
}
// Hope this helps