목록Switch (1)
컴공생의 다이어리
[자바, Java] switch-case문
자바(Java)의 switch-case문 switch-case문은 if-else if-else 문을 사용할 때 복잡하고 번거로운 부분을 가독성 좋게 구현할 수 있는 방법이다. 비교 조건이 특정 값이나 문자열인 경우에 사용한다. 각 조건이 만족되면 break문을 사용해 switch 블럭을 빠져나오도록 구현한다. 아래는 한달이 며칠인지 알려주는 것을 switch-case문을 사용해 구현한 코드이다. public class MonthSwitch { public static void main(String[] args) { int month = 10; int day; switch(month) { case 1:case 3: case 5: case 7: case 8: case 10: case 12: day = 31;..
Development/Java
2021. 7. 11. 00:01