+ 1
Java code
I need explaination of this code's output https://code.sololearn.com/ccOuU40lNajP/?ref=app
7 Respuestas
+ 5
i=1
j=0 //print 0
j=1 //print 1
j=2 //print 2
i=3
j=0//print 0
j=1//print 3
j=2// since i+j>4, therefore break statement will be executed.
i=5
j=0//since i+j>4, therefore break statement will be executed.
Final output:
01203
+ 4
Rael in for loop it's mentioned that we need to increment i with 2 after every iteration (i+=2).
So after i=1, in next iteration i=1+2=3. So, i will never be equal to 2.
+ 4
Rael I guess you got it.👍
+ 3
Himani oh i maybe know the concept already the for loop in the code doesnt have i++ so it means doesnt increase 1 each time,and
i = i+ 2 means i= 1+2 which is i = 3 and the 3 will remain at there untill the for loop return back.
+ 2
1 * 0 = 0
1 * 1 = 1
1 * 2 = 2
3 * 0 = 0
3 * 1 = 3
3 + 2 = 5 (break)
5 + 0 = 5 (break)
+ 1
Himani can i know after i = 1 is i = 2,mean while 2 +=2 ,ans is 4,why i = 3
+ 1
Himani
im really confused since
for(int i = 0,i < 5;i++)
will output: 01234