SwitchEx05-no break/switch+break

CODEDRAGON Development/Java

반응형

switch~case문과 switch~case~default 레이블 유무에 따른 출력결과 확인

   

소스코드

   

  1. public class SwitchEx05 {
  2.    
  3.         public static void main(String[] args) {
  4.    
  5.                 int n=3;
  6. //              int n=7;
  7. //              int n=10;
  8.                  
  9.                 switch(n)
  10.                 {
  11.                 case 1:
  12.                         System.out.println("First");
  13.                 case 2:
  14.                         System.out.println("Second");
  15.                 case 3:
  16.                         System.out.println("Thrid");
  17.                 case 4:
  18.                         System.out.println("Fourth");
  19.                 case 5:
  20.                         System.out.println("Fifth");
  21.                 case 6:
  22.                         System.out.println("Sixth");
  23.                 case 7:
  24.                         System.out.println("seventh");
  25.                          
  26.                 /*default:
  27.                         System.out.println("Ordinal Number");
  28.                         */             
  29.                 }
  30.                  
  31.                 System.out.println("I love JAVA!");
  32.         }
  33.    
  34. }

   

   

출력 결과

  

default레이블 없는 경우

default레이블이 있는 경우

n=3

  

  

n=7

  

  

n=10

  

  

   

   

   

   

반응형