JAVA代码输入月份出季节
时间: 2023-05-24 15:03:10 浏览: 131
A:以下是输入月份输出季节的Java代码:
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入月份(1-12):");
int month = input.nextInt();
input.close();
String season;
switch (month) {
case 12:
case 1:
case 2:
season = "冬季";
break;
case 3:
case 4:
case 5:
season = "春季";
break;
case 6:
case 7:
case 8:
season = "夏季";
break;
case 9:
case 10:
case 11:
season = "秋季";
break;
default:
season = "输入错误";
break;
}
System.out.println("您输入的月份是:" + month);
System.out.println("对应的季节是:" + season);
}
}
```
运行程序后,将提示用户输入月份(1-12),然后根据月份判断出对应的季节并输出。如果用户输入的月份不在1-12之间,则输出“输入错误”。
阅读全文