如誉扰果是String类型的,就转成date类型然后再.getMonth()+1获得月份
public class MonthAtSeason {public static void main(String[] args) {
int month=4 // 声明月份变量
switch (month) {
case 12:
case 1:
case 2:
System.out.println(month+"月份是冬季")
break
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
default:
System.out.println(month+"不是合法的掘雀月份数值"森散首此数)
break
}
}
}
package testimport java.util.Calendar
public class Test1 {
public static void main(String[] args) throws Exception {
Calendar now = Calendar.getInstance()
System.out.println(now.get(Calendar.MONTH) + 1)//根据月份,就可以判断季月了
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)