0
I am getting this same error in eclipse! (watch desk)
I have problems with arrays. I always get this same error Expection in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at MyClass.main(MyClass.java:20) My code: public class MyClass { public static void main(String[] args) { int array[] = new int[2]; array[1] = 132; array[2] = 31; System.out.println(array[1] + array[2]); } }
2 ответов
+ 1
indexing in array starts from 0
so the first item is 0, second item 1 and so on
array[0] = 132;
array[1] = 31;
System.out.println(array[0] + array[1]);
0
Thank you soooper alot!!!!