Java寫出生肖年判斷
更新時間:2018年02月24日 14:51:59 作者:彬菌
本篇文章主要給大家分享一篇關(guān)于用JAVA寫出生肖判斷的小功能,有興趣的跟著學習下。
以往我們用的最多的就是關(guān)于年或者日期的判斷,其實關(guā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("錯誤!請輸入大于0的數(shù)"); //不滿足以上條件的默認輸出這個語句 } } } catch(Exception e){ //捕捉異常 System.out.println("請正確輸入"); e.printStackTrace(); //打印異常信息在程序中出錯的位置及原因 } } }
大家可以測試下,如果還有任何不明白的地方可以在下方的留言區(qū)討論。
相關(guān)文章
淺談升級Spring Cloud到Finchley后的一點坑
這篇文章主要介紹了淺談升級Spring Cloud到Finchley后的一點坑,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-10-10Spring boot集成Go-FastDFS實現(xiàn)圖片上傳刪除等功能實現(xiàn)
這篇文章主要介紹了Spring boot集成Go-FastDFS實現(xiàn)圖片上傳刪除等功能實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-04-04java兩個integer數(shù)據(jù)判斷相等用==還是equals
本文主要介紹了java兩個integer數(shù)據(jù)判斷相等用==還是equals,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-12-12springboot Interceptor攔截器excludePathPatterns忽略失效
這篇文章主要介紹了springboot Interceptor攔截器excludePathPatterns忽略失效的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-07-07java實現(xiàn)基于UDP協(xié)議的聊天小程序操作
UDP是與TCP相對應(yīng)的協(xié)議,UDP適用于一次只傳送少量數(shù)據(jù)、對可靠性要求不高的應(yīng)用環(huán)境。正因為UDP協(xié)議沒有連接的過程,所以它的通信效率高;但也正因為如此,它的可靠性不如TCP協(xié)議高,本文給大家介紹java實現(xiàn)基于UDP協(xié)議的聊天小程序操作,感興趣的朋友一起看看吧2021-10-10