Search

switch & break

import java.util.Scanner; public class Ex07_SwitchBreak { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("์ •์ˆ˜ ์ž…๋ ฅ : "); int num = sc.nextInt(); // ์ž…๋ ฅ ๋ฐ›์€ ์ •์ˆ˜๋ฅผ 5๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€๊ฐ€ // 2๋ณด๋‹ค ์ž‘์œผ๋ฉด "*" ์ถœ๋ ฅ // ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด "**" ์ถœ๋ ฅ // - switch ๋ฌธ์„ ์ด์šฉํ•˜์‹œ์˜ค. switch ( num % 5 ) { case 0: case 1: System.out.println("*"); break; default: System.out.println("**"); break; } sc.close(); } }
Java
๋ณต์‚ฌ