package com.fqs.test;
import java.util.Random;
import java.util.Scanner;
public class hello {
public static void main(String[] args) {
//需求 程序自动生成一个1到100之间的随机数字A,键盘输入数B 猜数字
//1到10的随机数
Random r = new Random();
int ran = r.nextInt(10) + 1;
System.out.println("ran:"+ran);
//键盘输入
Scanner sc = new Scanner(System.in);
while(true){
System.out.println("请输入猜的数字");
int num = sc.nextInt();
if (ran < num) {
System.out.println("猜大了");
} else if (ran > num) {
System.out.println("猜小了");
} else {
System.out.println("猜对了");
break;
}
}
}
}
标签:数字,ran,System,键盘输入,猜错,num,println,out From: https://www.cnblogs.com/haha1988/p/17461333.html