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

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

mip版  关注:95  答案:3  悬赏:70

解决时间 2021-01-26 04:37

10232b6df8e3a72a7919babe7df798ef.png

已解决

2021-01-26 00:12

要求使用方法定义四个季节

最佳答案

df5b568482570cd4979693bfbb916a4c.png

2021-01-26 01:23

import java.io.BufferedReader;

import java.io.InputStreamReader;

public class Seases

{

int month;

public static void main(String[] args)

{

Seases s = new Seases();

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

BufferedReader in =new BufferedReader(new InputStreamReader(System.in));

while(true)

{

try

{

s.month = Integer.parseInt(in.readLine());

} catch (Exception e)

{

System.out.println("请输入整数");

}

Seases.identSeason(s.month);

}

}

public static void identSeason(int a)

{

if(a < 0 || a > 12)

{

System.out.println("请输入正确的月份,1-12之间");

}

else

{

switch((a - 1) / 3)

{

case 0 :System.out.println(a + "月为春季");

break;

case 1 :System.out.println(a + "月为夏季");

break;

case 2 :System.out.println(a + "月为秋季");

break;

case 3 :System.out.println(a + "月为冬季");

break;

}

}

}

}

全部回答

f8611fd31cfa21d9ed7b7bfb1e25dc86.png

1楼

2021-01-26 03:16

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

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 "错误";

}

}

}

b8a3ae2e1ff8e093398747edb843f6b8.png

2楼

2021-01-26 02:19

public static void season() {

scanner scanner = new scanner(system.in);

system.out.println("请输入月份");

int month = scanner.nextint();

if (month >= 1 && month <= 3) {

system.out.println("该季节为春季");

} else if (month >= 4 && month <= 6) {

system.out.println("该季节为夏季");

} else if (month >= 7 && month <= 9) {

system.out.println("该季节为秋季");

} else if (month >= 10 && month <= 12) {

system.out.println("该季节为冬季");

} else {

system.out.println("...");

}

scanner.close();

}

我要举报

如果感觉以上信息为低俗/不良/侵权的信息,可以点下面链接进行举报,我们会做出相应处理,感谢你的支持!

点此我要举报以上信息!

推荐资讯

大家都在看

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值