public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
System.out.println("猜数字大作战\r\n———————正在生成数字———————");
int num = 0, s = 0;
boolean isOk = false;
num = (int) (Math.random() * 101);
System.out.println("生成成功\r\n———————开始猜数字了———————");
System.out.println("请输入猜的数字(0-100):");
while (s++ < 4 && !isOk) {
System.out.print("第" + s + "次:");
try {
int n = sc.nextInt();
if (n > num) {
System.out.println("太大");
} else if (n == num) {
System.out.println("猜中了");
isOk = true;
} else {
System.out.println("太小");
}
} catch (Exception ex) {
System.out.println("输入的只能为数字");
}
}
System.out.println("结果是:"+num);
if (isOk) {
System.out.println("你真是太棒了");
} else {
if (s == 5) {
System.out.println("4次机会已经用完了");
}
System.out.println("失败了..要再来一次吗");
}
}
只会做到这里了