Java 猜数字游戏

import java.util.Scanner;

//猜电脑产生的随机数数

public class Dmoe1 {

public static void main(String[] args) {
int count = 0,t;
System.out.println("自动产生随机数的范围是1-100(包含1不包含100)");
System.out.println("5次没有猜中就会输掉游戏。");
int j = 1 + (int) (Math.random() * 99);
//System.out.println(j);// 作弊码
for ( t = 1; t < 6 ;t++) {
count++;
Scanner a = new Scanner(System.in);
int i = a.nextInt();
if (i < j) {
System.out.println("猜测数字过小!");
} else if (i > j) {
System.out.println("猜测数字过大!");
} else {
System.out.println("通过" + count + "次你就猜中了,你真是太棒了!!");
break;
}

}
if (t == 6) {
System.out.println("你的运气太差了不适合玩这类游戏!!");
}
}

}

猜你喜欢

转载自www.cnblogs.com/3w1z3/p/10907905.html