Saved Bookmarks
| 1. |
What is the output of the following code? int x = 64; int y = 0; while (x % 2 == 0) { y++; x = x / 2; } System.out.println(x + " " + y); |
|
Answer» LET's TAKE the VALUE of x= 2^6=64(2 RAISED to power 6) so in a while LOOP(after satifsy condition x%2==0) statement increase the value of y by 1 . and x value divde by 2. x=2^6, y=0 x=2^5, y=1 x=2^4, y=2 x=2^3, y=3 x=2^2, y=4 x=2^1, y=5 x=2^0=1, y=6 so while loop condition x%2==0 1%2==1:: not satisfy the condition. therfore come out from while loop and execute next statement and print . output: 1 6 |
|