I got this error. Though it may be very basic. I have declared array of length 3. Why does it still show an OutofBoundException error ?
public static void main(String[] args) {
int i;
String[] arr = new String[3];
Scanner input = new Scanner(System.in);
System.out.println("Please enter the name");
for (i = 0; i < 3; i++) {
arr[i] = input.nextLine();
}
System.out.println(arr[i]);
}
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at arraysPractice.Arr2.main(Arr2.java:21)