?? guessnumber.java
字號:
package day03;
import java.util.Scanner;
public class GuessNumber {
public static void main(String[] args) {
boolean flag = true;
while (flag) {
System.out.println("歡迎使用猜數(shù)游戲測試版");
System.out.println("\n 1開始 2退出\n\n");
Methed();
}
}// main()end
public static void Methed() {
Scanner sc = new Scanner(System.in);
int choice = sc.nextInt();
switch (choice) {
case 1:
start();// 調用下面定義的方法 start
break;
case 2:
System.out.println("********謝謝試用*****");
System.exit(0);
default:
System.out.println("對不起,您的輸入出錯!請輸入選擇 1 或 2");
Methed();
break;
}
}
public static void start() {
int j = (int) (Math.random() * 1000);
System.out.println(j);
System.out.println("你可以隨機輸入一個1~1000的數(shù)");
Scanner sc = new Scanner(System.in);
int k = 1;
while (true) {
if (k == 10) {
System.out.println("你太笨了,下次再來吧");
System.exit(0);
}
int i = sc.nextInt();
if (i < j) {
System.out.println("你蒙的數(shù)小了,再大點兒");
} else if (i > j) {
System.out.println("你蒙的數(shù)大了,再小點兒");
} else {
System.out.println("恭喜你,蒙對了");
System.out.println("\n 1 重新開始 2 退出");
Methed();
}
k++;
}// while 結束
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -