+ 3
for loop in java
for(int x=0; x<=10; x=x+2) { System.out.println(x); } how this condition of for loop print even number .I dont understand how x=x+2 print even number.
10 Answers
+ 5
it works like this......
x will start at 0 so first it will print 0, then the x=x+2 statement will execute.
so x = 0 + 2.
now x is 2.
it will print 2 now.
and everytime x will be increased by 2 and always print even numbers only.
+ 3
As x starts from zero which is an even no. Also if you even no. in an even no. the sum is even. Here in for loop you are adding 2 in zero then in 2 and so on till 10. So the outputs are even
+ 3
x equals its current value of x then increment by 2 to its value;
x=0
x=0+2
x=2+2
x=4+2
x=6+2 ect ect
+ 1
ok thanks, now its clear for me
+ 1
here ,fill the blank with the with correct answer to form a loop x=0,____x<20___,____(x) x+=2
0
please I need help
0
it works like this......
x will start at 0 so first it will print 0, then the x=x+2 statement will execute.
so x = 0 + 2.
now x is 2.
it will print 2 now.
and everytime x will be increased by 2 and always print even numbers only.
0
it work like this.
since 1st value of x=0 and that is given x=x+2; so un this case x print 2 that is even and next value of x become 2 so next again print 4 which is even no like that ...it will always print even number.
0
thanks again Rajesh, I appreciate .
- 1
Very nice