Ask your own question, for FREE!
Computer Science 13 Online
OpenStudy (anonymous):

I know this is a very simple piece of code, but I can't figure out what is going wrong =(

OpenStudy (anonymous):

http://pastebin.com/Lmzzx57Q

OpenStudy (anonymous):

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.

OpenStudy (anonymous):

http://ideone.com/qwAoe I wonder if casting the 1 to a byte will also work http://ideone.com/TiiY1 :(

OpenStudy (anonymous):

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.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!