import java.util.Scanner;//宣告Scanner 進來

public class UseScanner {

// 如何鍵盤輸入
          public static void main(String[] args) {

         int a;
         while(true)
        {

           int sys=(int)(Math.random()*100);
           Scanner sc=new Scanner(System.in); //31如果須鍵盤輸入須new一個記憶體
            System.out.println("\n請輸入0~99猜一個數字");
           int g = sc.nextInt();
          if(sys == g)
          {
            System.out.println("妳總共猜了猜對了"+a);
            a=0;
           }
           else
           {
           a+=1;
           System.out.println("猜錯了,答案是"+sys);
           }
          }

      }

}

arrow
arrow
    全站熱搜

    wealthy 發表在 痞客邦 留言(1) 人氣()