-
switch문Java/Script 2018. 2. 19. 20:10728x90
코드설명 : switch문
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657switch -> 값이 명확한 조건문이다. 조건에는 범위를 사용할 수 없다.switch(변수){case value1:변수의 값이 value1일 때의 실행문break; // break문이 없으면 break 걸릴때까지 진행한다.case value2:변수의 값이 value2일 때의 실행문break;default :모든 케이스에 맞지 않을때의 실행문}int number = 85;switch (number) {case 100:System.out.println("A+");break;case 90:System.out.println("B+");break;case 85:System.out.println("B"); // Bbreak;case 80:System.out.println("C");break;case 70:System.out.println("D");break;default:System.out.println("D보다낮아요");}char c = 'A';switch (c) {case 'A':System.out.println("A임"); // A임break;case 'B':System.out.println("B임");break;}String str = "ABC";switch (str) {case "DEF":System.out.println("str = " + str);break;case "ABC":System.out.println("str = " + str); // str = ABCbreak;}cs 728x90'Java > Script' 카테고리의 다른 글
while문 (0) 2018.02.19 for문 (0) 2018.02.19 if문 (0) 2018.02.19 HashMap 과 TreeMap (0) 2018.02.19 파일 및 폴더의 검색,생성,삭제,조사 (0) 2018.02.10