大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
大哥,switch case 不是这样用的,case后面a的值只能是确定的一个,比如:
网站的建设创新互联专注网站定制,经验丰富,不做模板,主营网站定制开发.小程序定制开发,H5页面制作!给你焕然一新的设计体验!已为成都宴会酒店设计等企业提供专业服务。
case 1:
System.out.println("春季");
break;
case 2:
System.out.println("春季");
break;
............
你要是想用范围做条件,用 if else 语句:
if(1=a=3){
System.out.println("春季");
}else if(4=a=6){
System.out.println("夏季");
}..........
else {
System.out.println("无季节匹配");
}
你好,按照你的要求代码如下,给出了注释,可以直接运行
public class Example10_3 {
public static void main(String args[]) {
// 从1月打到12月
for (int i = 1; i = 12; i++) {
System.out.println(getSeason(i));
}
}
// 根据月份获得季节
private static String getSeason(int month) {
switch ((month - 1) / 3) {
case 0:
return "春";
case 1:
return "夏";
case 2:
return "秋";
case 3:
return "冬";
default:
return "错误";
}
}
}
import java.io.*;
public class Month {
public static void main(String[] args) throws IOException{
BufferedReader indata=new BufferedReader(new InputStreamReader(System.in));
String month=indata.readLine();
//春:3-5
if(month.equalsIgnoreCase("March") || month.equalsIgnoreCase("Mar") || month.equalsIgnoreCase("April")
||month.equalsIgnoreCase("Apr") ||month.equalsIgnoreCase("May") ||month.equalsIgnoreCase("May"))
System.out.println("Spring");
//夏 6-8
else if(month.equalsIgnoreCase("June") || month.equalsIgnoreCase("Jun") || month.equalsIgnoreCase("July")
||month.equalsIgnoreCase("Jul") ||month.equalsIgnoreCase("August") ||month.equalsIgnoreCase("Aug"))
System.out.println("Summer");
//秋 9-11
else if(month.equalsIgnoreCase("Sempemter") ||month.equalsIgnoreCase("Sept") || month.equalsIgnoreCase("October")
||month.equalsIgnoreCase("Oct") ||month.equalsIgnoreCase("November") ||month.equalsIgnoreCase("Nov"))
System.out.println("Autumn");
//冬 12-2
else if(month.equalsIgnoreCase("December") || month.equalsIgnoreCase("Dec") || month.equalsIgnoreCase("January")
||month.equalsIgnoreCase("Jan") ||month.equalsIgnoreCase("February") ||month.equalsIgnoreCase("Feb"))
System.out.println("Winter");
}
}
/*
1月 January Jan.
2月 February Feb.
3月 March Mar.
4月 April Apr.
5月 May May
6月 June Jun.
7月 July Jul.
8月 August Aug.
9月 September Sept.
10月 October Oct.
11月 November Nov.
12月 December Dec.
*/