본문 바로가기
Beakjoon&프로그래머스/Java

[백준/Java] 2754번 학점계산

by 현장 2022. 8. 26.

-Code

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String grade = sc.next();
		float res = 0;
		char first = grade.charAt(0);
		
		if (first == 'A') {
			res = 4;
		} else if (first == 'B') {
			res = 3;
		} else if (first == 'C') {
			res = 2;
		} else if (first == 'D') {
			res = 1;
		} else {
			System.out.println(res);
			return;
			
		}
		
		char second = grade.charAt(1);
		
		if (second == '+') {
			res += 0.3;
		} else if (second == '-') {
            res -= 0.3;
        }
		
		System.out.println(res);
	}

}