- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx3TypeCasting.java
More file actions
Latest commit
18 lines (14 loc) · 688 Bytes
/
Copy pathEx3TypeCasting.java
File metadata and controls
18 lines (14 loc) · 688 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
packageJavaEntry;
publicclassEx3TypeCasting {
publicstaticvoidmain(String[] arg){
// Widening Casting (automatically) - converting a smaller type to a larger type size
// Narrowing Casting (manually) - converting a larger type to a smaller size type
byteexNumber = 9;
doublechangeByteTypeToDouble = exNumber;
System.out.println(exNumber + " to " + changeByteTypeToDouble); // Automatic casting: byte to double
shortpassMarks = 800;
shortgetMarks = 450;
floatmarkPercent = (float) getMarks / passMarks * 100.0f; // Manual casting: short to float
System.out.println(markPercent);
}
}