思路:
A\键盘输入,就需要导包
import java.util.Scanner;
B\建立一个类,名称为MonthDemo2
C\使用switch就可以实现。
switch(表达式){
case 值1:
语句
break;
case 值2:
语句
break;
case 值3:
语句
break;
... ...
default:
语句
break;
}
*/
import java.util.Scanner;//导包
class MonthMonth
{
public static void main(String[] args)
{
//创建对象,封装键盘输入
Scanner sc = new Scanner(System.in);
//提示语句
System.out.print("输入一个月份(1-->12):");
//调用方法,获取数据
int month = sc.nextInt();
//switch 语句
switch(month){
case 3:
case 4:
case 5:
System.out.println("月份"+month+"是夏季");break;
case 6:
case 7:
case 8:
System.out.println("月份"+month+"是夏季");break;
case 9:
case 10:
case 11:
System.out.println("月份"+month+"是秋季");break;
case 1:
case 2:
case 12:
System.out.println("月份"+month+"是冬季");break;
default:
System.out.println("月份"+month+"就不是月份该有的数值!@!#!$$!#$!#$#!%$!#");break;
}
System.out.println("继续要重新运行呦!!'.'");
}
}
import java.util.Scanner;
class SwitchDemo{
public static void main(String[] args){
for(int i=0;i<10;i++){
System.out.println("input numbers of the month !");
Scanner input = new Scanner(System.in);
int month = input.nextInt();
switch(month){
case 3:
case 4:
case 5:
System.out.println("Spring");
break;
case 6:
case 7:
case 8:
System.out.println("Summer");
break;
case 9:
case 10:
case 11:
System.out.println("Autumn");
break;
case 12:
case 1 :
case 2 :
System.out.println("Winter");
break;
default:System.out.println("input error !");
break;
}