2 Star 0 Fork 0

BESTI.IS.JAVA2018 / 20165325

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Exp1.java 1.21 KB
一键复制 编辑 原始数据 按行查看 历史
20165325 提交于 2018-03-31 16:20 . Exp1 codes
import java.util.Random;
import java.util.Scanner;
public class Exp1 {
public static void main(String[] args) {
Random rand = new Random();
int a = rand.nextInt(99) + 1;
System.out.println("已经产生一个1-100的随机数a,请猜猜看它是多少?");
Scanner g = new Scanner(System.in);
int b = 0;
do{
try {
b = g.nextInt();
while (b > 100 || b < 1) {
System.out.println("请检查你的输入!再试一次,确保它在1-100之间:");
b = g.nextInt();
}
}
catch (Exception e) {
System.out.println("输入发生异常:" + e.getMessage());
System.out.println("请检查你的输入!再试一次,确保它在1-100之间:");
g = new Scanner(System.in);
continue;
}
if (b>a) {
System.out.println("不对,太大了!");
}
if (b<a) {
System.out.println("不对,太小了!");
}
}while (a != b);
System.out.println("猜对了!2333333333333333333333333\na = "+a);
}
}
Java
1
https://gitee.com/BESTI-IS-JAVA-2018/20165325.git
git@gitee.com:BESTI-IS-JAVA-2018/20165325.git
BESTI-IS-JAVA-2018
20165325
20165325
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891