ex1 Using "switch-case"

System.out.println("학점을 입력해주세요");
			int score = sc.nextInt();
			int yuk = score/10;
			
			switch(yuk) {
			case 10 :
			case 9 :
				System.out.println(score + "점은 A 입니다.");
				break;
			case 8 :
				System.out.println(score + "점은 B 입니다.");
				break;
			case 7 :
				System.out.println(score + "점은 C 입니다.");
				break;
			case 6 :
				System.out.println(score + "점은 D 입니다.");
				break;
			default :
				System.out.println("press F to pay respect");
				break;
			}

 

ex2 using "if-else if"

	System.out.println("학점을 입력해주세요");
			int score = sc.nextInt();
			
    if (score>=90)
				System.out.println(score + "점은 A 입니다.");
			else if (score>=80)
				System.out.println(score + "점은 B 입니다.");
			else if (score>=70)
				System.out.println(score + "점은 C 입니다.");
			else if (score>=60)
				System.out.println(score + "점은 D 입니다.");
			else 
				System.out.println(score + "점은 F 입니다.");

'java > java exercise' 카테고리의 다른 글

Generate multiplication table of a given number  (0) 2020.01.25
It will thank you until you're satisfied.  (0) 2020.01.25
Print multiplication table  (0) 2020.01.25
Dice Game  (0) 2020.01.25
Changing Letter case  (0) 2020.01.25