大哥,switch case 不是這樣用的,case后面a的值只能是確定的一個(gè),比如:
網(wǎng)站的建設(shè)創(chuàng)新互聯(lián)專(zhuān)注網(wǎng)站定制,經(jīng)驗(yàn)豐富,不做模板,主營(yíng)網(wǎng)站定制開(kāi)發(fā).小程序定制開(kāi)發(fā),H5頁(yè)面制作!給你煥然一新的設(shè)計(jì)體驗(yàn)!已為成都宴會(huì)酒店設(shè)計(jì)等企業(yè)提供專(zhuān)業(yè)服務(wù)。
case 1:
System.out.println("春季");
break;
case 2:
System.out.println("春季");
break;
............
你要是想用范圍做條件,用 if else 語(yǔ)句:
if(1=a=3){
System.out.println("春季");
}else if(4=a=6){
System.out.println("夏季");
}..........
else {
System.out.println("無(wú)季節(jié)匹配");
}
你好,按照你的要求代碼如下,給出了注釋?zhuān)梢灾苯舆\(yùn)行
public class Example10_3 {
public static void main(String args[]) {
// 從1月打到12月
for (int i = 1; i = 12; i++) {
System.out.println(getSeason(i));
}
}
// 根據(jù)月份獲得季節(jié)
private static String getSeason(int month) {
switch ((month - 1) / 3) {
case 0:
return "春";
case 1:
return "夏";
case 2:
return "秋";
case 3:
return "冬";
default:
return "錯(cuò)誤";
}
}
}
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.
*/
本文標(biāo)題:判斷季節(jié)的java代碼,java根據(jù)月份判斷是哪個(gè)季節(jié)
當(dāng)前鏈接:http://m.kartarina.com/article30/hsdspo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷(xiāo)、動(dòng)態(tài)網(wǎng)站、標(biāo)簽優(yōu)化、域名注冊(cè)、響應(yīng)式網(wǎng)站、定制開(kāi)發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)