

다중 if문을 이용하여 계절 입력시 결과값에 맞는 계절 출력하여라!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class ex04_다중if문1 { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
System.out.print("월 입력 : "); | |
int month = sc.nextInt(); | |
if(month==12||month==1||month==2) { | |
System.out.println(month +"월은 겨울입니다!"); | |
}else if(month==3||month==4||month==5){ | |
System.out.println(month + "월은 봄입니다!"); | |
}else if(month==6||month==7||month==8){ | |
System.out.println(month + "월은 여름입니다!"); | |
}else if(month==9||month==10||month==11){ | |
System.out.println(month + "월은 가을입니다!"); | |
}else { | |
System.out.println("다시 입력해주세요"); | |
} | |
} | |
} |
'java 코딩' 카테고리의 다른 글
dowhile 홀수 짝수 판별 (0) | 2021.12.14 |
---|---|
switch문 사계절 입력 (0) | 2021.12.14 |
java if 조건문 예제 (0) | 2021.11.22 |
삼항연산자 예제 (상자의 개수구하기) (0) | 2021.11.21 |
삼항연산자 (짝수,홀수 판별) (1) | 2021.11.20 |