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

TOP

返回列表