반응형
Q. switch-case를 이용하여 성적을 입력받고 학점을 출력하는 프로그램을 만들어보세요.
90점 이상 = A학점
80점 이상 = B학점
70점 이상 = C학점
60점 이상 = D학점
60점 미만 = F학점
import java.util.Scanner;
public class On {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("점수를 입력하세요 >>");
int num = sc.nextInt();
switch(num/10){
case 9: case 10:
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등급 입니다.");
}
}
}
반응형