- 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);

17th May 2021, 4:50 PM
Nacereddine Drici
Nacereddine Drici - avatar
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 .
17th May 2021, 5:00 PM
TOLUENE
TOLUENE - avatar
+ 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
17th May 2021, 4:52 PM
TOLUENE
TOLUENE - avatar
+ 2
note that this question is tagged for JavaScript but it is not JavaScript
13th Jun 2021, 1:15 PM
Lisa F
Lisa F - avatar
0
SAYED🇧🇩🇵🇸 ❤ Please can you explain me what does that means : for(int i=0;i<3;i++) I am struggling with that 😢
17th May 2021, 4:57 PM
Nacereddine Drici
Nacereddine Drici - avatar