swich case 예제
cf.코드에서 아래 파란 부분 수정하면 됩니다.
import java.util.Scanner;
public class SwitchTest {
public static void main(String[] args) {
int korean=0;
int english=0;
int math=0;
Scanner s = new Scanner(System.in);
System.out.println("국어 점수를 입력하세요 : ");
korean = s.nextInt();
System.out.println("영어 점수를 입력하세요 : ");
english = s.nextInt();
System.out.println("수학 점수를 입력하세요 : ");
math = s.nextInt();
int score = korean+english+math;
int avg = score/3;
System.out.println("===================================");
System.out.println("국어"+"\t"+"영어"+"\t"+"수학"+"\t"+"평균"+"\t"+"등급");
System.out.println("===================================");
switch(avg/10){
case 10:
case 9: System.out.println(korean+"\t"+english+"\t"+math+"\t"+avg+"\t"+" A"); break;
case 8: System.out.println(korean+"\t"+english+"\t"+math+"\t"+avg+"\t"+" B"); break;
case 7: System.out.println(korean+"\t"+english+"\t"+math+"\t"+avg+"\t"+" C"); break;
case 6: System.out.println(korean+"\t"+english+"\t"+math+"\t"+avg+"\t"+" D"); break;
default : System.out.println(korean+"\t"+english+"\t"+math+"\t"+avg+"\t"+" F");
}
System.out.println("===================================");
}
}