i-zro / Dongguk-ICE-2020_2

1 stars 1 forks source link

융프 midterm 개념 #8

Closed i-zro closed 4 years ago

i-zro commented 4 years ago

20 - 09 -22

비교 연산자

ex) 3<5 true 반환

ex) 1!=3 true 반환

논리 연산자

중첩 if - else 문

image

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        int score = sc.nextInt();
        int grade = sc.nextInt();
        if(score >= 60) {
            if(grade == 4) {
                if(score >= 70) {
                    System.out.println("합격");
                }
                else {System.out.println("불합격");}
            }
            else {System.out.println("합격");}
        }
        else {System.out.println("불합격");}
    }
}

switch 문

image

ex) if-else문 switch문으로 바꾸기

image

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        int score = sc.nextInt();

        switch(score/10) {
        case 10: //break 안쓰면 아래 case랑 똑같은 결과 나옴
        case 9:
            System.out.println('A');
            break;
        case 8:
            System.out.println('B');
            break;
        case 7:
            System.out.println('C');
            break;
        case 6:
            System.out.println('D');
            break;
        default:
            System.out.println('F');
        }
        sc.close();
}
}