class A {
public static void main (String[] args) {
// code ...
System.out.println(B.fun1());
// code ...
}
class B {
// code ...
public int fun1(){
return C.fun2();
}
class C {
// code ...
public int fun2() {
int u = 0;
for(int k= 0; arr[k] != null ; k++,System.out.println("k="+k)) {
int a = arr[k].getVal();
String s = Integer.toString(a);
if (s.equals(("1"))) {
u = u + 10;
} else {
u = u + a;
}
}
return u;
}
}
I have a code of same structure as shown above and when main
executes the output is:
k=1
k=2
k=3
the return value u
from fun1
as printed in main
is:
30 //depends on getVal()
but after this output it also shows this
k=1
k=2
k=1
k=2
k=1
k=2
and I receive an ArrayIndexOutOfBoundsException
. How is this possible?
My question is why I am getting this k=1 k=2 k=1 ... thing
CODE:https://drive.google.com/open?id=1aZYv7qqYd1___fXA92lbtLO5WccI9wz6
How to reproduce: Things are random so try to play couple of times.