I just started learning java. I use the Eclipse IDE and JDK 7. I just learnt about arrays and was trying to run this code:
public class Testproj {
public static void main(String[] args){
int[] values = new int[4];
values[1] = 10;
values[2] = 20;
values[3] = 30;
values[4] = 40;
System.out.println(values[1]);
System.out.println(values[2]);
System.out.println(values[3]);
System.out.println(values[4]);
}
}
But I get this compile time error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at Testproj.main(Testproj.java:8)
Why am I getting this error and how can I eliminate it?