I know this is a very simple piece of code, but I can't figure out what is going wrong =(
when you add 1 to a byte, java (tries to) convert to int b = b + 1; if you increment it, it stays a byte b += 1; don't ask why. nothing to see here. move along now.
http://ideone.com/qwAoe I wonder if casting the 1 to a byte will also work http://ideone.com/TiiY1 :(
From Java documentation you get this... byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). So, if you are doing an loop from 1 to 10, you can use byte i instead for int i. You are getting an error because you are trying to and int to byte, which is a different data type for compiler.
Join our real-time social learning platform and learn together with your friends!