This is a snippet of code construct in java which gives a simple output :-----
1 2 3 4 5 |
|
The answer to the question is the value printed i.e. the final value of 'k'. Note : Its a good question so please do not spoil its fun by using a computer to solve it.Have fun...
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
When the loop value increases then it continues till the value of k reaches maximum a byte can contain i.e. k=127. That all bits are one but the sign bit is zero.
Sign bit zero represents "+" i.e. +ve integer. Sign bit one represents "-" i.e. -ve integer. Now when we call the "k++" and as all the bits are "1" except the sign bit the k++ changes it also to one and thus a -ve number i.e. -128 is generated . This acts as the exit condition for the loop and after that "-128" is printed.