java学习---猜数字游戏(自动生成随机数)
2021-01-15 00:16
标签:tin print stat exe out please else 死循环 random package exercise; import java.util.Random; public class my_guss_number { java学习---猜数字游戏(自动生成随机数) 标签:tin print stat exe out please else 死循环 random 原文地址:https://www.cnblogs.com/D007/p/12938967.html
import java.util.Scanner;
public static void main(String[] args) {
Random ra = new Random();
int n = ra.nextInt(10); //自动生成随机数
Boolean flag = true;
while (flag) {
System.out.println("please input number a:");
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
if (a > n) {
System.out.println("it is so big!");
}else if (a System.out.println("it is so small!");
}else {
System.out.println("good luck!");
flag = false; //防止产生死循环
}
}
}
}
文章标题:java学习---猜数字游戏(自动生成随机数)
文章链接:http://soscw.com/index.php/essay/42020.html