返回列表 發帖
  1. import java.io.Console;
  2. public class ch29
  3. {
  4.    public static void main(String args[])
  5.    {
  6.      Console console=System.console();
  7.      String str;
  8.      int a=1,b=99;
  9.      int ans=38;
  10.      int guess;
  11.      while(true)
  12.      {
  13.         System.out.print("猜一個"+a+"~"+b+"的數字: ");
  14.         guess=Integer.parseInt(console.readLine());
  15.         a=(guess<ans)?guess:a;
  16.         b=(guess>ans)?guess:b;
  17.         if(guess!=ans)
  18.         {
  19.            str=(guess>ans)?"猜得太大了!":"猜得太小了!";
  20.            System.out.println(str);
  21.            continue;
  22.         }
  23.      System.out.println("賓果!");
  24.            break;
  25.      }
  26.    }
  27. }
複製代碼

TOP

返回列表