+ 10
{Help} Explain This Please😉
int x=0; int y=2; do{ x+=y; } while (x<4); System.out.println(++x); Output is 5 Explain it please😉😉
16 Antworten
+ 25
@Khairul
loop1)x=2 & condition is true
loop2)x=4 & condition is false ... so loop stops
print (++4) ... print 5
@Nitish
x+=2; means x=x+2;
+ 12
What about x+=y. ??
+ 8
when x comes out of do-while loop, its value will be 4. In system.out.print method it is first incremented to 5 (since its prefix)and the printed to 5
+ 8
first x=0. since its do-while, loop get executed once before condition, then x=2. then it check for condition, it is sactisfied. then again statement in loop is executed and x=4 now. x+=2 is equivalent to x=x+2
+ 7
Thanks😉😉
+ 7
because ++x will print value after incrementing x.
hence, ++4=5.
+ 6
The output of this code is 5 because the code will keep on running as long as x<4, but as soon. as x is equalled to 5 the program stop running.
+ 5
x+=y means x=x+y
+ 4
x =+y means x= x+y
+ 4
on the first time we get
x=0+2 // now the value of x sets to 2
entering while loop
it gets incremented and then displayed as 3
ON 2 time now the value of x is 2
so now
x=2+2 // this produces result x=4
on entering the while loop
x value gets incremented to 5 and displayed
+ 3
If you try to do it by step you have :
x=0;
y=2;
x += y; (which means x = x +y;)
which makes the x == 2
Then you check if x<4 (it is true, as 2<4),
so you repeat what's inside the awhile brackets.
So we again have x+= y, which as a result, gives x==4. Now the while condition is false, as 4 < 4 is a false statement, so the loop stops. Now we print the x value is 4 and we print ++x, which raises x's value by one and returns the new value, so it returns 5
+ 2
@gaurav answer my question
+ 1
Shohsanam
First iteration of the loop:
x=1+2=3
As 3< 7, the loop run for the second time.
2nd iteration:
x=3+2=5
As 5<7, the condition is true. The loop iterates for 3rd time.
3nd iteration:
x=5+2=7
0
correct answer for below question
int x = 1;
while (x <=
7
) {
System.out.println("in a loop");
x
++;
}
0
Currect 9
- 1
How many times will this loop run?
int x = 1;
for ( ; x < 7; )
{
x+=2;
}
WHAT IS THIS