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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | /* * if Phrase(if문) */ package Java_ch4; public class IfPhrase { public static void main(String[] args) { int score = 90; if (score > 80) { System.out.println("higher than 80"); System.out.println("A rank"); } if (score < 80) { System.out.println("less than 80"); System.out.println("B rank"); } System.out.println(score); } } /* result higher than 80 A rank 90 */ package Java_ch4; public class IfElsePhrase { public static void main(String[] args) { int score = 70; if (score > 80) { System.out.println("higher than 80"); System.out.println("A rank"); } else { System.out.println("less than 80"); System.out.println("B rank"); } } } /* result less than 80 B rank */ /* * if else if else */ package Java_ch4; public class IfElseIfElse { public static void main(String[] args) { int score = 81; if (score >= 90) { System.out.println("higher than 90"); System.out.println("A grade"); } else if (score >= 80) { System.out.println("higher than 80"); System.out.println("B grade"); } else if (score >= 70) { System.out.println("higher than 80"); System.out.println("C grade"); } else { System.out.println("F grade"); } } } /* higher than 80 B grade * | cs |
'문돌이의 IT > 자바(Java)' 카테고리의 다른 글
자바(Java) 중첩 if 조건문 (2) | 2017.02.10 |
---|---|
자바(Java) 조건문 if else, math.random() (0) | 2017.02.09 |
자바(Java) 삼항연산자 (0) | 2017.01.04 |
자바(java) 비교연산자와 논리연산자 (0) | 2017.01.03 |
자바(Java) 변수, 연산자 (0) | 2017.01.02 |