我是靠谱客的博主 高大微笑,这篇文章主要介绍Java基础猜数游戏 (运用do while循环)(eclipse下),现在分享给大家,希望可以做个参考。

小白基础的猜数游戏
电脑随机给出1~100之间的数
玩家进行猜数
电脑会给与 “偏大,偏小“的提示;
代码其中就Math.random()是随机函数
number是电脑给的数

Scanner in= new Scanner(System.in);
		int number=(int)(Math.random()*100+1);
		int a;
		int count=0;
		do{
			a=in.nextInt();
			count++;
			if(a>number)
			{
				System.out.println("偏大");
			}
			else if(a<number)
			{
				System.out.println("偏小");
			}
		}while(a!=number);
		System.out.println("恭喜你猜对了,你猜了"+count+"次");

	}

大家快试试,感觉不错的啊!!!
给个赞呗。。。。。。。。。。。

最后

以上就是高大微笑最近收集整理的关于Java基础猜数游戏 (运用do while循环)(eclipse下)的全部内容,更多相关Java基础猜数游戏内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部