项目 1、使用 if…else if…else 语句实现判断某月是哪个季节的功能
1)编写一个类 Example11
2)定义一个变量 month 用于存储月份。
3)用 if 条件语句,判断这个月份在哪一个季节并输出结果,如:春季是 3、
4、5 月,夏季是 6、7、8 月,秋季是 9、10、11 月,冬季是 12、1、2 月
4)由于一年只有 12 个月,所以要过滤除 1-12 以外的月份值
源代码:
文件名称:Example11.java
类名称:Example11
方法名称:main
Package cn.edu.hbuas.mingbilian;
public class {
private static int n;
public static void main(String[] args) {
int month = 1;//输入月份
if(month==3||month==4||month==5)
{System.out.println(month+"月属于春季");//3、4、5 月是春季
}
else if(month==6||month==7||month==8)
{System.out.println(month+"月属于夏季");//6、7、8 月是夏季
}
else if(month==9||month==10||month==11)
{System.out.println(month+"月属于秋季");//9、10、11 月是冬季
}
else if(month==12||month==1||month==2)
{System.out.println(month+"月属于冬季");//12、1、2 月是冬季
}
else{
System.out.println("不存在这个月份");//除了 1~12 月,其他数字都属于错误
月份
评论0
最新资源