【Java】一個有趣的數字遊戲。

來源:互聯網
上載者:User

標籤:port   str   png   分享   package   img   nbsp   bsp   math   

 1 package com.xt.homework.hw09; 2 import java.util.Scanner; 3 /** 4  * 4. 猜數字遊戲。隨機產生一個1—100的整數, 5  *     讓使用者去猜,猜大了(或者猜小了)都有提示; 6  *     直到使用者猜對,提示成功,程式結束。 7  *  8  * @author 天耀二期 9  *              楊勃隆10  */11     public class HomeWork04 { 12     public static void main(String[] args){13     double b = Math.random();14      b*=100;15      if((int)(b+0.5)>(int)b){16      b=(int)b+1;}17      else{18      b=(int)b;}19      while(1==1){20     System.out.println("請輸入您猜的數:");21     Scanner scan = new Scanner(System.in);22     int a = scan.nextInt();23     if(a>b){24         System.out.println("---您猜大了---");}25     if(a<b){26         System.out.println("---您猜小了---");}27     if(a==b){28         System.out.println("++恭喜您,猜對了++");29         break;}30         }31     }

枯燥的學習,玩玩遊戲也挺不錯的!


 

 

【Java】一個有趣的數字遊戲。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.