本文編寫一個java數字猜拳的小游戲,具體實現很簡單
聶榮網站建設公司創新互聯,聶榮網站設計制作,有大型網站制作公司豐富經驗。已為聶榮1000+提供企業網站建設服務。企業網站搭建\外貿網站制作要多少錢,請找那個售后服務好的聶榮做網站的公司定做!
package guenum; import java.util.ArrayList; import java.util.Scanner; public class Demo { // private static Object list; public static void main(String ad[]) { System.out.println("-------------------------------------小游戲-------------------------------------"); System.out.println("-----------------------系統內置了一個99到177之間的一個隨機數-----------------------"); int rm=(int) (Math.random()*78 +99); Scanner sc=new Scanner(System.in); int input_number; int n=0; int t=0; boolean value=false; int[] temp=new int[30]; while(!value) { System.out.print("輸入你所猜的數據:"); try { input_number=sc.nextInt(); temp[n]=input_number; t=n; n++; if(input_number==rm) { value=true; }else if(input_number<rm) { System.out.println("小了,再猜!"); }else if(input_number>rm) { System.out.println("大了,再猜!"); } }catch(Exception e) { System.out.println(e); return; } } System.out.println("你總共用了"+n+ "次猜中!"); System.out.println("你所猜的數列如下"); System.out.print("{"); while(n--!=0) { System.out.print(temp[n]+"," ); } System.out.print("}"); System.out.println("\n"); System.out.println("本次猜測活動評價:"); if(t==1) { System.out.println("你太聰明了!"); }else if(2<=t && t<=5) { System.out.println("不錯,再接再厲!"); }else if(t>=6) { System.out.println("要努力啊!"); } } }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持創新互聯。
網站題目:java實現數字猜拳小游戲
文章網址:http://m.2m8n56k.cn/article36/jdshsg.html
成都網站建設公司_創新互聯,為您提供品牌網站設計、網站導航、網站設計、App設計、云服務器、網站策劃
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯