Need to print out:
0
-1
1
-2
2
-3
3
-4
4
...
Write the code below for this case:
for(int i=0;i<=4;i++){
for(int k=-i;;k=Math.abs(i)){
process(k);
if(i==k)break;
}
}
Is there any way to optimize this algorithm? (process
method can only be called once in a loop)