Computer Science, asked by sattar4228, 1 year ago

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);

Answers

Answered by nitish8089
8
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
Similar questions