package Lecture2;
public class OperationMain_ifswitch {
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
46
47
48
49
50
51
52
53
54
55
56
public static void main(String[] args) {
// <3항 연산자>
int a = 10;
int b = 7;
int max = (a > b) ? a : b;
System.out.println(max);
b=11;
max = (a > b) ? a : b;
System.out.println(max); // max = (a > b) ? a : b;가 없으면 10으로 출력
// 3항 연산자 : ______? 선택1 : 선택2;
// 조건 T F
// <출력값이 3개 이상일 때>
/* c가 d보다 크다면 c 출력
* c가 d보다 작다면 d 츨략
* c와 d가 같다면 0 출력
*/
int c = 5;
int d = 5;
System.out.println(c>d?c:(c<d?d:0));
System.out.println(c==d?0:(c>d?c:d));
/*
* 중첩된 if문
if(c>d) { // c > d
System.out.println(c);
} else { // c <= d 중첩된 if-else
if(c<d) {
System.out.println(d); // c < d
} else {
System.out.println(0); // c == d
}
}
*/
if(c>d) { // c > d
System.out.println(c);
} else if(c<d) {
System.out.println(d);
} else {
System.out.println(0);
}
// <if문>
int x = 10, y = 5;
System.out.println("MAX : " + (x>y?x:y));
if (x > y) {
System.out.println("MAX : " + x);
} else {
System.out.println("MAX : " + y);
} // 문법 자동맞춤 : ctrl+shift+F
}
}