Hey guys I'm currently making a program where it will reverse the input from the user. Currently my code is
import java.util.*;
public class Reverse {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
List<String> input = new ArrayList<>();
while (in.hasNextLine())
input.add(in.nextLine());
for (int x = 0; input.size() >= x; x++) {
String reverse = "";
for (int z = input.get(x).length(); z > 0; z--) {
reverse += input.get(x).charAt(z - 1);
}
System.out.println(reverse);
}
}
}
But I'm getting the error where it says
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at Reverse.main(Reverse.java:12)*
Any help would be greatly appreciated thanks!