Post

@EclipseJavaIDE @java Infinite loop since the byte won’t be implicitly to int and after it reaches 127 it will start from -128 and so on
English

@EclipseJavaIDE endless loop: byte range is -128..127. Every value is < 128 (int).
Eventually, may throw OOM (heap) because S strings grows until consumes full heap size.
English

@EclipseJavaIDE I would think that it is 128. Initially, I thought it would be 128 / 8 = 16, but then I thought again...
English

@EclipseJavaIDE I think it won't compile. When b is 127, b++ will try to assign 128 to a byte and that can only be done with an explicit typecast.
English

@EclipseJavaIDE Infinite loop. Same code in c#? Expect a 128 on the console ;-)
English

@EclipseJavaIDE @java 128
Because the program loop 128 times
The counter b begin with 0 and the loop end when b asigned with 128
Last valid counter is 127
From 0 to 127 = 128
English

@EclipseJavaIDE Probably zero because byte is signed and 128 == -1 so the loop won't run at all
English

@EclipseJavaIDE The loop will run forever and s will keep changing it’s value between-MAX_INT and MIN_INT. Sop will never be reached.
English

@EclipseJavaIDE Infinite loop.. it will stuck in the loop ranging from -128 to 127... It will come down to -128 after adding 1 in 127.
English

@EclipseJavaIDE @java It will compiled successfully and start infinite loop because b will increased on every itetation and must stop repeat when b value equals or greater than 128 after next increase. But byte maximum positive value is 127, next value of b will -128 and condition will never worked.
English

@EclipseJavaIDE @java the main role is played by the number 128. if you give 127, it will print 1 to 127 but with 128 it goes into infinite loop
English

@EclipseJavaIDE @java I'm surprised at all the comments saying infinite loop. I thought bytes are usually 8 bits...
Oh nvm I just remembered the sign bit is in there too.
But are Java bytes also 8 bits? I read somewhere that Java string uses 16 bit representation.
Time to read about bits and bytes...
English

@EclipseJavaIDE infinite loop, b will reset to 0 before reaching 128
English

@EclipseJavaIDE @java It will not cause an infinite loop as the Integer "s" will overflow 😁
English


















