效果图如下:
输入月份,输出月份所属季节:
源代码如下:
import java.util.Scanner;
/*输入月份,输出月份所属季节
*3,4,5为春季
*6,7,8为夏季
*9,10,11为秋季
*12,1,2为冬季
*/
public class Demo5{
public static void main(String [] args){
System.out.println("请输入月份:");
Scanner input = new Scanner(System.in);
int a = input.nextInt();
switch (a){
case 2:
case 3:
case 4:
System.out.println("月份是春季");
break;
case 5:
case 6:
case 7:
System.out.println("月份是夏节");
break;
case 8:
case 9:
case 10:
System.out.println("月份是秋季");
break;
case 11:
case 12:
case 1:
System.out.println("月份是冬季");
break;
}
}
}