Question: This is java, I got a question, when I store byteX into shortX then I display shortX, I get -128. Even though shortX have more
This is java,
I got a question, when I store byteX into shortX then I display shortX, I get -128. Even though shortX have more bits than byteX, why it is not 128,
I got the same problem, I tried also to have byteX to be equal to 20000 , but when I stored it in shortX. I got a completely different answer (32), why it is not 128?


+ 0 BOutline X 4 # practice Practice S main Practice.java X X .classpath Labclass.java 2 3 public class Practice { 50 public static void main(String[] args) , 6 7 8 9 byte bytex; 10 bytex = (byte)128; //bytex has 0111 1111; 11 short shortX; 12 shortX = byteX; // shortx has 13 // 0000 0000 0111 1111 14 int intX; 15 intX = byteX; 16 long longX; 17 longX = intX; 18 float floatX; 19 floatx = intX; 20 double doubleX; 21 doubleX = intX; 22 System.out.println(shortx); 23 24 25 } 26 27 } 28 Problems @ Javadoc Declaration Console X
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
