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代码
本文地址:https://www.cdcxhl.com/article10/dogdggo.html

成都网站建设公司_创新互联,为您提供外贸网站建设软件开发App设计网站策划静态网站服务器托管

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

微信小程序开发