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

TOP

返回列表