import java.util.Random;
import java.util.Scanner;
public class GussNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Random nu = new Random();
int[] arr = {10, 20, 30, 40, 50, 60, 70};//定义一个数组arr[]
int t1 = arr[nu.nextInt(arr.length)];//arr[数组中的第(随机)几个]
int t = nu.nextInt(1, t1 + 1);
while (true) {
System.out.printf("请输入一个整数【1-%d】:", t1);
int scc = sc.nextInt();
if (scc > t) {
System.out.println("大了");
} else if (scc < t) {
System.out.println("小了");
} else {
System.out.println("恭喜你猜对了");
break;
}
}
}
}
java猜数小程序
最新推荐文章于 2024-11-02 11:13:42 发布