Search

switch with String

import java.util.Scanner; public class Ex06_Grade { public static void main(String[] args) { // ํ•™์ ์„ ์ž…๋ ฅ๋ฐ›์•„, ์ ์ˆ˜ ๊ตฌ๊ฐ„์„ ์ถœ๋ ฅํ•˜์‹œ์˜ค. // A : 90~100์ ์ž…๋‹ˆ๋‹ค. Scanner sc = new Scanner(System.in); System.out.print("ํ•™์  : "); // String (๋ฌธ์ž์—ด) ์ฐธ์กฐ ์ž๋ฃŒํ˜• String grade = sc.next(); // * ๋ฌธ์ž, ์ •์ˆ˜, ๋ฌธ์ž์—ด์€ switch ๋ฌธ์˜ ์กฐ๊ฑด๊ฐ’์œผ๋กœ ๊ฐ€๋Šฅ // * ์‹ค์ˆ˜(float, double) ์กฐ๊ฑด๊ฐ’์œผ๋กœ ๋ถˆ๊ฐ€๋Šฅ switch (grade) { case "A": System.out.println("90~100์ ์ž…๋‹ˆ๋‹ค."); break; case "B": System.out.println("80~89์ ์ž…๋‹ˆ๋‹ค."); break; case "C": System.out.println("70~79์ ์ž…๋‹ˆ๋‹ค."); break; case "D": System.out.println("60~69์ ์ž…๋‹ˆ๋‹ค."); break; case "F": System.out.println("60์  ๋ฏธ๋งŒ์ž…๋‹ˆ๋‹ค."); break; default: System.out.println("A~F ์‚ฌ์ด์˜ ๋ฌธ์ž๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); break; } sc.close(); } }
Java
๋ณต์‚ฌ