๐Ÿ•ธ Algorithm/๐Ÿ•ธ ๋ฐฑ์ค€ BaekJoon

[๋ฐฑ์ค€][java][9498][์‹œํ—˜ ์„ฑ์ ]

๋‰ด์ด NUEY 2023. 9. 24. 20:22
๋ฐ˜์‘ํ˜•

 

import java.util.Scanner;

// 9498	์‹œํ—˜ ์„ฑ์ 
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int score = sc.nextInt();
	
		String result = "";
		
		sc.close();
	
		switch (score / 10) {
		case 10: 
		case 9 : result = "A";
			break;
		case 8 : result = "B";
			break;
		case 7 : result = "C";
			break;
		case 6 : result = "D";
			break;
		default: result = "F";
			break;
		}
		
		System.out.println(result);
	}
}
  • if()๋ฌธ ๋ณด๋‹ค ๊ฐ„๊ฒฐํ•˜๊ฒŒ ์ž‘์„ฑํ•˜๊ธฐ ์œ„ํ•ด switch()๋ฅผ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.
  • case์—์„œ ๋น„๊ต์—ฐ์‚ฐ์ž ex.> ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๊ธฐ์— ์ž…๋ ฅ๊ฐ’ score๋ฅผ 10์œผ๋กœ ๋‚˜๋ˆ„์–ด ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.
  • 90/10์€ 9, 70/10์€ 7์ด๊ธฐ์— case์™€ ์ผ์น˜ํ•˜๋Š” ๊ฐ’์„ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • break;๋ฅผ ๋ฐ˜๋“œ์‹œ ์ ์–ด์ฃผ์–ด์•ผ ์•„๋ž˜ case๋ฅผ ๊ฑด๋„ˆ๋œ๋‹ˆ๋‹ค.
  • case 10:์—์„œ break์„ ์ ์ง€ ์•Š์•˜๊ธฐ์—, 100์ด ์ž…๋ ฅ๋˜๋ฉด 10์€ case 9์˜ result = "A";๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
  • case์— ์ผ์น˜ํ•˜๋Š” ๊ฐ’์ด ์—†๋‹ค๋ฉด default: ๊ตฌ๋ฌธ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
๋ฐ˜์‘ํ˜•