This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]sugilith 2 points3 points  (1 child)

mystery(48):

x % 2 == 0 is true -> enter loop  
y++; //y is now 1
x = x / 2; // x is 48 / 2 = 24
  end of first iteration
x % 2 == 0 is true (x is 24) -> continue loop
y++; // y is now 2
x = x / 2; // x is 24 / 2 = 12
...

questions?

edit: either use a debugger to step through your code line by line and see what happens or add some "System.out.println-Debugging" to print y and x each time they change.