public class Switch01 {//Switch문 public static void main(String[] args){ java.util.Scanner input= new java.util.Scanner(System.in); System.out.print("정수 입력 : "); int a = input.nextInt(); switch(a){ 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 ");//마지막엔 쓸필요없음 //break가 없으면 순차적으로 다른것도 실행됨 } } }
public class FlowEx11 {//switch로 학점 public static void main(String[] args){ int score = 88; char grade = ' ';//공백 switch(score/10){ //0~100 -> 0~10 case 10: //grade='A';break;생략 case 9 : grade='A';break; case 8 : grade='B';break; case 7 : grade='C';break; case 6 : grade='D';break; default : grade='F'; } System.out.println("당신의 학점은" + grade + "입니다."); } }