-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcasting.java
More file actions
27 lines (20 loc) · 782 Bytes
/
Copy pathcasting.java
File metadata and controls
27 lines (20 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public class casting {
public static void main(String[] args){
byte byteValue = 20;
short shortValue = 55;
int intValue = 888;
long longValue = 23355;
float floatValue = 8834.5f;
float floatValue2 = (float)99.3;
double doubleValue = 32.4;
System.out.println(Byte.MAX_VALUE);
intValue = (int)longValue;
System.out.println(intValue);
doubleValue = intValue;// all good examples of casting
System.out.println(doubleValue);
intValue = (int)floatValue;
System.out.println(intValue);
byteValue = (byte)128;//Shows how casting to byte 1 after the max value itll wrap around to the smallest value it can hold
System.out.println(byteValue);
}
}