返回列表 發帖
  1. import java.io.Console;
  2. public class ch116
  3. {
  4.   public static void main (String args[])
  5.   {   
  6.      int x, big, small, i, a;
  7.      big=99;
  8.      Small=1;
  9.      i=1;
  10.      System.out.print("數字遊戲, 猜一介於1~99間的數字");
  11.       System.out.println();
  12.        Console console=System.console();
  13.       System.out.print("請猜一個0~99的數: ");
  14.       a=Integer.parseInt(console.readLine());


  15.       x=((int)(Math.random()*100+1));  //產生介於1~99的隨機亂數;

  16.         while(a==x)(
  17.       if(a>x)
  18.         {
  19.            big==a ;
  20.            System.out.println("猜一介於"+big"~"+small"間的數字");
  21.            Console console=System.console();
  22.       a=Integer.parseInt(console.readLine());
  23.            i++;
  24.         }else if(a<x)
  25.         {
  26.            small==a;
  27.            System.out.println("猜一介於"+big"~"+small"間的數字");
  28.            Console console=System.console();
  29.       a=Integer.parseInt(console.readLine());
  30.            i++;

  31.         }
  32.          else
  33.         {

  34.         }

  35.         )
  36.           System.out.println(+a);
  37.             System.out.println("恭喜你猜對了,你共猜了"+i"次");


  38. }
  39.   }
複製代碼

TOP

返回列表