根据指定月份,打印该月份所属的季节。 3,4,5 春季 6,7,8 夏季 9,10,11 秋季 12, 1, 2 冬季 if和switch各写一版
1、public class Month{
public static void main(String args[]){
for (int i = 1;i <= 12 ;i++ )
{
if (i == 3 || i == 4 || i == 5)
{
System.out.println(i+"月份是春季");
}
if (i == 6 || i == 7 || i == 8)
{
System.out.println(i+"月份是夏季");
}
if (i == 9 || i == 10 || i == 11)
{
System.out.println(i+"月份是秋季");
}
if (i == 12 || i == 1 || i == 2)
{
System.out.println(i+"月份是冬季");
}
}
}
}
2、public class Month{
public static void main(String args[]){
for (int i = 1;i <= 12;i++ )
{
switch(i)
{
case 1:System.out.println("1月份是冬季");break;
case 2:System.out.println("2月份是冬季");break;
case 3:System.out.println("3月份是春季");break;
case 4:System.out.println("4月份是春季");break;
case 5:System.out.println("5月份是春季");break;
case 6:System.out.println("6月份是夏季");break;
case 7:System.out.println("7月份是夏季");break;
case 8:System.out.println("8月份是夏季");break;
case 9:System.out.println("9月份是秋季");break;
case 10:System.out.println("10月份是秋季");break;
case 11:System.out.println("11月份是秋季");break;
case 12:System.out.println("12月份是冬季");break;
default:;
}
}
}
}
//default的后面还是要加: 之后在加;
最新文章
- 纯PHP实现定时器任务(Timer)
- Oracle数据库——数据库安全性管理
- Authentication token manipulation error for ubuntu ubuntu-16.04.1-desktop-amd64
- maven3实战之设置HTTP代理
- 查看当前hadoop的版本号
- Android窗口管理服务WindowManagerService计算窗口Z轴位置的过程分析
- J2SE学习小结
- java解析上传的excel
- leetcode range sum query
- 【python】spark+kafka使用
- Entity Frame Code First 简易教程
- Jenkins报错&#39;Gradle build daemon disappeared unexpectedly&#39;的问题解决
- eclipse项目运行文件位置
- 20155326刘美岑 2016-2017-2 《Java程序设计》第二周学习总结
- [ 9.9 ]CF每日一题系列—— 259A黑白棋盘检查问题
- 利用Regsvr32绕过Applocker的限制策略
- 【ORACLE 】查询被锁住的对象,并结束其会话
- Hibernate5笔记3--详解Hibernate的API
- 学习c++ofstream和ifstream
- php redis安装使用
热门文章
- 组件中的data为什么不是一个对象而是一个函数?
- Quartz 2D CGPattern学习笔记
- 读《高情商修炼手册》有感 output
- python多线程的问题
- ACCESS中查询语句:查询所得数据另存到一个指定目录下的文件夹里,并新建新的文件
- SQL 查找是否”存在”,别再用 COUNT 了,真的很费时间!
- prometheus-alertmanager 告警规则
- Oracle数据库字符集与国家字符集
- Android Custom View使用Databinding
- C++ Error:C2011: &#39;struct&#39; type redefinition