返回列表 發帖
  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.             break;
  21.         }
  22.         System.out.println("恭喜你猜對了!");
  23.     }
  24. }
複製代碼

TOP

返回列表