+ 3
I cannot understand complex code in java
i know about all veriable, method, loop as well, I understand how they are used on code.. but when I see nested loop or condition statement, I cannot understand them... how can i be expert in java please help me guys please
3 Answers
+ 2
in that case, use a debugger or add control test outputs to better understand the current state of the variables between lines of code
0
don't worry practice more... u can understand all...
what is zemiak said is good idea... debugger shows line by code execution.....
0
To analyse that use a pen n paper, first look out only one loop most inner one or outer one, i think outer one is better, then first write down starting values before loop start, initial condition, step count, expected final value if possible, go through every line by line then write down every result until loop complete. Now apply with all inner loops one by one til end... If you practice for 4,5 different loops after that it would be easy to you analyse what is happening ..
I think this some help you...
Ex:
for(int i=0;i<5;i++)
for(int j=0; j<5;j++)
a[i][j]=i+j;
In first i=0,
J=0 to 4
a[0][j]=0+j;
i=1, a[1][j]=1+j, j=0 to 4
i=2, a[2][j]=2+j, j=0 to 4
i=3, a[3][j]=3+j, j=0 to 4
i=4, a[4][j]=4+j, j=0 to 4
In this way array assigned...