-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperationPromotionExample.java
More file actions
45 lines (38 loc) Β· 1.36 KB
/
OperationPromotionExample.java
File metadata and controls
45 lines (38 loc) Β· 1.36 KB
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
38
39
40
41
42
43
44
45
package ch02.sec09;
public class OperationPromotionExample {
public static void main(String[] args) {
byte result1 = 10 + 20;
// μ»΄νμΌ λ¨κ³μμ μ°μ°
System.out.println("result1 : " + result1); // 30
byte b1 = 10;
byte b2 = 20;
int result2 = b1 + b2;
// int νμ
μΌλ‘ λ³ν ν μ°μ°
System.out.println("result2 : " + result2); // 30
byte b3 = 10;
int i1 = 100;
long l1 = 1000L;
long result3 = b3 + i1 + l1;
// long νμ
μΌλ‘ λ³ν ν μ°μ°
System.out.println("result3 : " + result3); // 1110
char c1 = 'A';
char c2 = 1;
int result4 = c1 + c2;
// int νμ
μΌλ‘ λ³ν ν μ°μ°
System.out.println("result4 : " + result4); // 66
System.out.println("result4 : " + (char) result4); // B
int i2 = 10;
int result5 = i2 / 4;
// μ μ μ°μ°μ κ²°κ³Όλ μ μ
System.out.println("result5 : " + result5); // 2
int i3 = 10;
double result6 = i3 / 4.0;
// double νμ
μΌλ‘ λ³ν ν μ°μ°
System.out.println("result6 : " + result6); // 2.5
int i4 = 1;
int i5 = 2;
double result7 = (double) i4 / i5;
// double νμ
μΌλ‘ λ³ν ν μ°μ°
System.out.println("result7 : " + result7); // 0.5
}
}