Code:
class Test{
public static void main(String[] args){
int x=0;
int [] num = {1,1,3,3,3,3};
int [] a = new int [4];
for(int i = 0; i < num.length-1; i++){
x =++num[i];
a[i++] = x;
System.out.println("num :"+ i+" " + x);
}
for (int j = 0; j< a.length; j++){
System.out.println(a[j]);
}
}//end main
}//end class
num :1 2
num :3 4
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at Test.main(Love.java:10)
Process completed.*/
Problem
I am going trought the array and counting all the elements which are the same. The answer given above is correct, 1 one occurs twice an 3 occurs 4 times. Why I am getting an out of bounds error?
