我是靠谱客的博主 活力小甜瓜,这篇文章主要介绍Random随机数的简单应用,现在分享给大家,希望可以做个参考。

public static void main(String []args) {
	Scanner in = new Scanner(System.in);
	int num =(int)Math.random()*100+1;使电脑产生的数字在[1,100]内
	int a = in.nextInt();
	while(true) {
	if(a==num ) {
		System.out.println("waooooo!");
		break;
	}else if(a<num){
		System.out.println("小了再来::::");
		a=in.nextInt();
	}else {
		System.out.println("大了再来::::");
		a=in.nextInt();
	}
	
	}

注:不要忘记导包,还有Math.random本身的取值范围是0~1之间,方便使用所以放大100倍。

最后

以上就是活力小甜瓜最近收集整理的关于Random随机数的简单应用的全部内容,更多相关Random随机数内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(144)

评论列表共有 0 条评论

立即
投稿
返回
顶部