+ 22

Doubt in output plss help.{Solved}

Can anybody plss tell how come the output is 66 for the following code?? class Test { public static void main(String[] args)     {  int i = 0, j = 9; do { i++;   if (j-- < i++) {  break;   }  } while (i < 5); System.out.println(i + "" + j);  } }

30th Apr 2020, 7:23 AM
Shruti
Shruti - avatar
8 Respuestas
+ 10
Suyash Pandey I already got the answer 2 months ago...😅 Thanks By the way 👍🙂
16th Jul 2020, 1:50 PM
Shruti
Shruti - avatar
+ 3
1: i = 0, j = 9 i = 1 if (9 < 1) // not true break i = 2, j = 8 2: i = 2, j = 8 i = 3 if (8 < 3) // not true break i = 4, j = 7 3: i = 3, j = 7 i = 4 if (7 < 4) // not true break i = 5, j = 6 4: i = 5, j = 6 i = 6 if (6 < 6) // not true break i = 6, j = 6 in this while(i < 5) cause it to stop because i = 6 therefore i = 6, j = 6
30th Apr 2020, 7:48 AM
RKK
RKK - avatar
0
RKK check your values for i in steps 3 and 4 again.
30th Apr 2020, 8:01 AM
ChaoticDawg
ChaoticDawg - avatar
0
ChaoticDawg this is just an idea on how to dry code. well the best option for this would be to use a debugger.
30th Apr 2020, 8:16 AM
RKK
RKK - avatar
0
I understand what you're doing, just was trying to bring to your attention that there is a small error in your explanation. Check the value of I going into your step 3. It leaves step 2 with a value of 4, but you have it starting out at 3 in the next step. This makes it so that when the 3rd step is done it is 5 instead of 6. Step 4 doesn't actually happen.
30th Apr 2020, 8:23 AM
ChaoticDawg
ChaoticDawg - avatar
0
Well I also don't get it sister
16th Jul 2020, 7:12 AM
Suyash Pandey
Suyash Pandey - avatar
0
𝕊𝕠𝕝𝕠𝕝𝕖𝕒𝕣𝕟𝕖𝕣 okay 🙂....well....sista do you know anythin' 'bout hacking or ethical hacking?
17th Jul 2020, 1:30 AM
Suyash Pandey
Suyash Pandey - avatar
0
𝕊𝕠𝕝𝕠𝕝𝕖𝕒𝕣𝕟𝕖𝕣 hey can you please say ....why if I am messaging anyone then it's showing you're not allowed!!
17th Jul 2020, 5:54 AM
Suyash Pandey
Suyash Pandey - avatar