*/
import java.util.Scanner;
import java.util.Random;
class Demo {
public static void main(String[] args) {
//1.生产随机数
Random ra = new Random();
int gussNumber = ra.nextInt(100)+1;
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个1-100的正数");
public class Demo_Random {
public static void main(String[] args) {
// 1.生产随机数
Random ra = new Random();
int gussNumber = ra.nextInt(100) + 1;
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个1-100的正数");
for (int i = 1; i < 6; i++) {
int enterNumber = sc.nextInt();
if (i==5) {
System.out.println("对不起,您的机会用完了");
break;
}else if(i < 5) {
if (gussNumber == enterNumber) {
System.out.println("恭喜你答对了");
break;
}else if (gussNumber > enterNumber) {
System.out.println("小了");
System.out.println("您还有"+(5-i+"次机会"));
}else if (gussNumber < enterNumber) {
System.out.println("大了");
System.out.println("您还有"+(5-i+"次机会"));
}
}
}
}
}
按你的要求改了一下,