- 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;
- }
- break;
- }
- System.out.println("恭喜你猜對了");
- }
- }
複製代碼 |