조건이 정수, 문자열 값으로 그 값에 따라 수행 결과가 달라지는 경우
if-else if- else와 같은 의미로 수행
if(rank == 1){ medalColor ='G'; else if(rank ==2 ){ medalColor ='S'; } else if(rank == 3) { medalCollor = 'B'; } else { medalColor = 'A;' switch(rank) { case1:medalColor = 'G'; break; case2:medalColor = 'S'; break; case3:medalColor = 'B'; break; default:medalColor ='A'; } package ifexample; import java.util.Scanner; public class SwitchCaseEx { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int rank = scanner.nextInt(); char medalColor ='A'; switch(rank) { case 1: medalColor ='G'; System.out.println("금메달"); break; case 2: medalColor ='S'; System.out.println("은메달"); break; case 3: medalColor ='B'; System.out.println("동메달"); break; default: medalColor ='A'; } System.out.println(rank+ "등은"+medalColor+"메달 입니다" ); } package ifexample; import java.util.Scanner; public class SwitchCaseEX2 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in);//표준 입력용 int month = scanner.nextInt(); int day; switch(month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: day = 31; break; case 2: day = 28; break; case 4: case 6: case 11: day = 31; break; default: System.out.println("Error"); day= 0; } System.out.println(month+"월은"+day+"일입니다."); } }