十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
你好,按照你的要求代码如下,给出了注释,可以直接运行
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:空间域名、网页空间、营销软件、网站建设、桑珠孜网站维护、网站推广。
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 "错误";
}
}
}
大哥,switch case 不是这样用的,case后面a的值只能是确定的一个,比如:
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("无季节匹配");
}
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.
*/
public class Test {
public static void main(String[] args) {
String s = getSeason(4);
System.out.println(s);
}
public static String getSeason(int n) {
String s = "";
if (n 0 n 13) {
if (n == 2 || n == 3 || n == 4) {
s = "春天";
}
if (n == 5 || n == 6 || n == 7) {
s = "夏天";
}
if (n == 8 || n == 9 || n == 10) {
s = "秋天";
}
if (n == 11 || n == 12 || n == 1) {
s = "冬天";
}
} else {
s = "输入月份有误!";
}
return s;
}
}