网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

java四季代码 javagui代码

让大家一个java非常简单的编程:根据输入1到12之间的数字,判断是春夏秋冬哪个季节

你好,按照你的要求代码如下,给出了注释,可以直接运行

创新互联公司主营怀仁网站建设的网络公司,主营网站建设方案,手机APP定制开发,怀仁h5微信小程序搭建,怀仁网站营销推广欢迎怀仁等地区企业咨询

public class Example10_3 {

public static void main(String args[]) {

// 从1月打到12月

for (int i = 1; i = 12; i++) {

System.out.println(getSeason(i));

}

}

// 根据月份获得季节

private static String getSeason(int month) {

switch ((month - 1) / 3) {

case 0:

return "春";

case 1:

return "夏";

case 2:

return "秋";

case 3:

return "冬";

default:

return "错误";

}

}

}

JAVA编写,1. 分别使用if-else-if语句和switch语句编程,确定某一月在哪个季节。

话不多说,直接上代码。

Scanner sc = new Scanner(System.in);

System.out.print("请输入月份 : ");

String monthStr = sc.next();

int month = Integer.parseInt(monthStr);

if (month = 3 month = 5) {

System.out.println("春季");

} else if (month = 6 month = 8) {

System.out.println("夏季");

} else if (month = 9 month = 11) {

System.out.println("秋季");

} else if (month == 12 || month = 2) {

System.out.println("冬季");

} else {

System.out.println("没有该月份 " + month);

}

java编程,输入月份判断季节

代码喝注释如下:

public static void main(String[] args) {  System.out.print("Please input the month to check:");  int month = new Scanner(System.in).nextInt();//月份//月份不在1~12的情况,提醒输入错误  if (month = 0 || month  12) {   System.out.println("Error! month must be between 1 and 12!");  } 

//1-3月是春天

else if (month = 3) {   System.out.println("Month " + month + " is in Spring!");  } 

//4-6月是夏天

else if (month = 6) {   System.out.println("Month " + month + " is in Summer!");  } 

//7-9月是秋天

else if (month = 9) {   System.out.println("Month " + month + " is in Autumn!");  } 

//10-12月是冬天

else {   System.out.println("Month " + month + " is in Winter!");  } }


分享文章:java四季代码 javagui代码
本文来源:http://bjjierui.cn/article/dogdggo.html

其他资讯