标题: 每日练习 [打印本页] 作者: 222222222222 时间: 2016-6-3 14:53 标题: 每日练习 import java.util.Scanner;
class SwitchCase
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个月份:");
int a = sc.nextInt();
String x = getJijie(a);
System.out.println(a+"月份对应的季节为:"+x);
System.out.println("请输入1-7中的数字");
int b = sc.nextInt();
String week = weekDay(b);
System.out.println(b+"数字对应的星期为:"+week);
}
public static String getJijie(int x)
{
String jj;
switch(x)
{
case 12:
case 1:
case 2:
jj = "冬季";
break;
case 3:
case 4:
case 5:
jj = "春季";
break;
case 6:
case 7:
case 8:
jj = "夏季";
break;
case 9:
case 10:
case 11:
jj = "秋季";
break;
default :
jj = "错误的输入";
break;
}
return jj;
}
public static String weekDay(int week)
{
String we;
switch (week)
{
case 1:
we = "星期一";
break;
case 2:
we = "星期二";
break;
case 3:
we = "星期三";
break;
case 4:
we = "星期四";
break;
case 5:
we = "星期五";
break;
case 6:
we = "星期六";
break;
case 7:
we = "星期七";
break;
default:
we = "错误的输入!";
break;