- import java.io.Console;
- public class ch116
- {
- public static void main (String args[])
- {
- int x, big, small, i, a;
- big=99;
- Small=1;
- i=1;
- System.out.print("數字遊戲, 猜一介於1~99間的數字");
- System.out.println();
- Console console=System.console();
- System.out.print("請猜一個0~99的數: ");
- a=Integer.parseInt(console.readLine());
- x=((int)(Math.random()*100+1)); //產生介於1~99的隨機亂數;
- while(a==x)(
- if(a>x)
- {
- big==a ;
- System.out.println("猜一介於"+big"~"+small"間的數字");
- Console console=System.console();
- a=Integer.parseInt(console.readLine());
- i++;
- }else if(a<x)
- {
- small==a;
- System.out.println("猜一介於"+big"~"+small"間的數字");
- Console console=System.console();
- a=Integer.parseInt(console.readLine());
- i++;
- }
- else
- {
- }
- )
- System.out.println(+a);
- System.out.println("恭喜你猜對了,你共猜了"+i"次");
- }
- }
複製代碼 |