📄 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("欢迎使用猜数游戏测试版");
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的数");
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("你蒙的数小了,再大点儿");
} else if (i > j) {
System.out.println("你蒙的数大了,再小点儿");
} else {
System.out.println("恭喜你,蒙对了");
System.out.println("\n 1 重新开始 2 退出");
Methed();
}
k++;
}// while 结束
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -