0
Can someone please explain how does this code work?
for(int a=1, b=1; b<8; a+=b, b=a-b){ System.out.print(a + " "); }
1 Resposta
+ 3
start values:
a = 1
b = 1
condition when for loop ends:
b < 8
what happens with a and b:
a += b
b = a - b
1. a = 1, b = 1
print 1
2. a = 2, b = 1
print 2
3. a = 3, b = 2
print 3
4. a = 5, b = 3
print 5
5. a = 8, b = 5
print 8
6. a = 13, b = 8 -> end loop
Output:
1 2 3 5 8