I was making a code that makes some unique integers in a string and i suddenly ran into an exception and i don't quite get what is the problem here, because i was almost done. And now what is happening i don't know.
Here's my code:
String[] res = new String[12];
int[] ia = {1, 6, 9};
int[] ai = {97, 79, 8};
int[] a = new int[10];
for(int i = 0; i < a.length; i++){
a[i] = (ia[new Random().nextInt(3)] ^ (ai[new Random().nextInt(3)] * i));
for(int j = 0; j < res.length; j++){
if(a[i] >= j){
res[j * i] = "J:" + (a[i] * a[new Random().nextInt(10)]); //exception
} else if(a[i] <= j){
res[j * i] = "J:" + (-(a[i] * a[new Random().nextInt(10)]));
}
}
}
Here is the exception that is thrown:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 12
at testy.main(unique.java:15)