+ 1

Java code

I need explaination of this code's output https://code.sololearn.com/ccOuU40lNajP/?ref=app

6th Jun 2019, 12:05 PM
Tzion
Tzion - avatar
8 Answers
+ 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
6th Jun 2019, 12:16 PM
Himani
+ 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.
6th Jun 2019, 12:29 PM
Himani
+ 4
Rael I guess you got it.👍
6th Jun 2019, 1:36 PM
Himani
+ 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.
6th Jun 2019, 1:32 PM
Tzion
Tzion - avatar
+ 2
1 * 0 = 0 1 * 1 = 1 1 * 2 = 2 3 * 0 = 0 3 * 1 = 3 3 + 2 = 5 (break) 5 + 0 = 5 (break)
6th Jun 2019, 10:41 PM
zemiak
+ 1
Himani can i know after i = 1 is i = 2,mean while 2 +=2 ,ans is 4,why i = 3
6th Jun 2019, 12:23 PM
Tzion
Tzion - avatar
+ 1
Himani im really confused since for(int i = 0,i < 5;i++) will output: 01234
6th Jun 2019, 1:26 PM
Tzion
Tzion - avatar