- 1
😁😁😁 Please can you tell me why the answer of this question is 3 ?
What is the output of this code? int a=0; for(int i=0;i<3;i++) { a=a+i; } System.out.print(a);
4 Answers
+ 6
for(int i=0;i<3;i++)
⭕Declared an int type variable and assigned 0 to it
⭕ condition . the loop will run as long as i<3 condition is true
⭕ i++; increment value of i by one after each iteration .
Please do the lesson on for loops .
+ 2
1st iter
a = a+0
a = 0
2nd iter
a = a + 1
a = 0 + 1
a = 1
3rd iter
a = a+2
a = 1+2
a = 3
It's final value of a
+ 2
note that this question is tagged for JavaScript but it is not JavaScript
0
SAYED🇧🇩🇵🇸 ❤ Please can you explain me what does that means :
for(int i=0;i<3;i++)
I am struggling with that 😢