-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx3TypeCasting.java
More file actions
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
package JavaEntry;
public class Ex3TypeCasting {
public static void main(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
byte exNumber = 9;
double changeByteTypeToDouble = exNumber;
System.out.println(exNumber + " to " + changeByteTypeToDouble); // Automatic casting: byte to double
short passMarks = 800;
short getMarks = 450;
float markPercent = (float) getMarks / passMarks * 100.0f; // Manual casting: short to float
System.out.println(markPercent);
}
}