Imagine you're working on a Java program and you have a large numerical value stored in a data type that can handle larger numbers. You need to store this value in a less capable data type, but you need to make sure it fits - otherwise, data may be lost. Given this, can you fill in the blanks in the provided code to properly cast the long value to an int, and then the int to a byte?
Type casting
Casting long to byte with intermediate int
Report a typo
Fill in the gaps with the relevant elements
public class TypeCastingExample {
public static void main(String[] args) {
longValue = 300;
intValue = (int) longValue;
byteValue = (byte) intValue;
System.out.println("Long value: " + longValue);
System.out.println("Int value: " + intValue);
System.out.println("Byte value: " + byteValue);
}
} ___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.