- import java.io.Console;
- public class ch28
- {
- public static void main(String args[])
- {
- Console console=System.console();
- String str;
- int ans=38;
- int guess;
- while(true)
- {
- System.out.print("猜一個1~99的數字: ");
- guess=Integer.parseInt(console.readLine());
- if(guess!=ans)
- {
- str=(guess>ans)?"猜得太大了!":"猜得太小了!";
- System.out.println(str);
- continue;
- }
- System.out.println("賓果!");
- break;
- }
- }
- }
複製代碼 |