Java寫出生肖年判斷
更新時(shí)間:2018年02月24日 14:51:59 作者:彬菌
本篇文章主要給大家分享一篇關(guān)于用JAVA寫出生肖判斷的小功能,有興趣的跟著學(xué)習(xí)下。
以往我們用的最多的就是關(guān)于年或者日期的判斷,其實(shí)關(guān)于生肖的判斷有點(diǎn)類似年限的判斷。
下面是全部代碼:
import java.util.Scanner; public class Zodiac { public static void main(String[] args){ Scanner input=new Scanner(System.in);//聲明掃描儀變量 System.out.println("請輸入年份");//系統(tǒng)提示輸入 try{ //監(jiān)聽異常 while(true){ int birth = input.nextInt()%12; //用戶輸入%12在再轉(zhuǎn)換 switch(birth){ case 0:System.out.println("猴年");break; case 1:System.out.println("雞年");break; case 2:System.out.println("狗年");break; case 3:System.out.println("豬年");break; case 4:System.out.println("鼠年");break; case 5:System.out.println("牛年");break; case 6:System.out.println("虎年");break; case 7:System.out.println("兔年");break; case 8:System.out.println("龍年");break; case 9:System.out.println("蛇年");break; case 10:System.out.println("馬年");break; case 11:System.out.println("羊年");break; default :System.out.println("錯(cuò)誤!請輸入大于0的數(shù)"); //不滿足以上條件的默認(rèn)輸出這個(gè)語句 } } } catch(Exception e){ //捕捉異常 System.out.println("請正確輸入"); e.printStackTrace(); //打印異常信息在程序中出錯(cuò)的位置及原因 } } }
大家可以測試下,如果還有任何不明白的地方可以在下方的留言區(qū)討論。
相關(guān)文章
淺談升級(jí)Spring Cloud到Finchley后的一點(diǎn)坑
這篇文章主要介紹了淺談升級(jí)Spring Cloud到Finchley后的一點(diǎn)坑,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-10-10Spring boot集成Go-FastDFS實(shí)現(xiàn)圖片上傳刪除等功能實(shí)現(xiàn)
這篇文章主要介紹了Spring boot集成Go-FastDFS實(shí)現(xiàn)圖片上傳刪除等功能實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04java兩個(gè)integer數(shù)據(jù)判斷相等用==還是equals
本文主要介紹了java兩個(gè)integer數(shù)據(jù)判斷相等用==還是equals,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12springboot Interceptor攔截器excludePathPatterns忽略失效
這篇文章主要介紹了springboot Interceptor攔截器excludePathPatterns忽略失效的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07java實(shí)現(xiàn)基于UDP協(xié)議的聊天小程序操作
UDP是與TCP相對(duì)應(yīng)的協(xié)議,UDP適用于一次只傳送少量數(shù)據(jù)、對(duì)可靠性要求不高的應(yīng)用環(huán)境。正因?yàn)閁DP協(xié)議沒有連接的過程,所以它的通信效率高;但也正因?yàn)槿绱耍目煽啃圆蝗鏣CP協(xié)議高,本文給大家介紹java實(shí)現(xiàn)基于UDP協(xié)議的聊天小程序操作,感興趣的朋友一起看看吧2021-10-10