java - why is this loop working infinitely? -
class kk{ public static void main(string args[]){ int n=0; (byte = 0; i<=255; i++) { n++; } system.out.println(n); } }
the above loop goes on infinitely . appreciate if reply why ?
because byte values in range of [-128, 127]
.
hence, when byte 127 incremented overflows -128 , loop continues indefinitely.
java
No comments:
Post a Comment