-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypeCasting.java
More file actions
37 lines (33 loc) · 1002 Bytes
/
typeCasting.java
File metadata and controls
37 lines (33 loc) · 1002 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
28
29
30
31
32
33
34
35
36
37
package miscellaneous;
public class typeCasting {
public static void main(String[] args) {
//type conversion(implicit)
byte b = 10;
short s = b;
int i = s;
long l = i;
float f = l;
double d = f;
//output
System.out.println("byte: "+b);
System.out.println("short: "+s);
System.out.println("int: "+i);
System.out.println("long: "+l);
System.out.println("float: "+f);
System.out.println("double: "+d);
//type casting(explicit)
double db = 10.5;
float fl = (float)db;
long lg = (long)fl;
int in = (int)lg;
short sr = (short)in;
byte by = (byte)sr;
//output
System.out.println("double: "+db);
System.out.println("float: "+fl);
System.out.println("long: "+lg);
System.out.println("int: "+in);
System.out.println("short: "+sr);
System.out.println("byte: "+by);
}
}