- 월을 입력받아 계절을 출력하는 프로그램
- 콘솔뷰에서 월을 입력받는다.(1 ~ 12)
- 3 ~ 5: "00월은 봄입니다.", 6~8: "00월은 여름입니다.", 9~11: "00월은 가을입니다.", 나머지 12, 1, 2: "00월은 겨울입니다." 라고 출력한다.
package com.dream.controls;
import java.util.Scanner;
public class ControlEx09 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int month = 0;
String str = "";
System.out.println("월을 입력하면 계절을 알 수 있습니다.");
System.out.print("월 입력: ");
month = in.nextInt();
if(month >= 3 && month <= 5) {
str="봄";
}else if(month >= 6 && month <= 8) {
str="여름";
}else if(month >= 9 && month <= 11) {
str="가을";
}else if(month == 12 || month == 1 || month == 2) {
str="겨울";
}else {
str="계절을 입력하세요.";
}
if(month >= 1 && month <= 12) {
System.out.println(month + "월은 "+str+"입니다.");
}
System.out.println(str);
}
}