Loop front and back in one line
You can also check this out :
int a=1;
for(int i=0 ; i>-1 ; i+=a){
if (i==4)a=-a;
System.out.print(i +" ");
}
output :
0 1 2 3 4 3 2 1 0
for (int i = -4; i <= 4; i++) {
System.out.println(4 - Math.abs(i));
}