Loading... 玩法:输入1-100以内的随机数,系统会判断偏大或者偏小,然后重新输入直至输入与系统给出的随机数一致时,程序结束运行,程序会统计你一共用了多少次猜对结果。 Tips:猜数方法正确的话7次就能猜对。 ```java import java.util.Scanner; public class MathGame { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int number = (int)(Math.random()*100+1); int a,count = 0; do { a =in.nextInt(); count = count + 1; if(a>number) { System.out.println("偏大"); } else if(a<number) { System.out.println("偏小"); } }while( a !=number ); System.out.println("恭喜你猜对了,一共猜了"+count+"次"); } } ```<hr class="content-copyright" style="margin-top:50px" /><blockquote class="content-copyright" style="font-style:normal"><p class="content-copyright">版权属于:Feihong</p><p class="content-copyright">本文链接:<a class="content-copyright" href="https://www.feihong.me/archives/18.html">https://www.feihong.me/archives/18.html</a></p><p class="content-copyright">转载时须注明出处及本声明</p></blockquote> 最后修改:2019 年 12 月 31 日 11 : 05 PM © 允许规范转载 赞赏 如果觉得我的文章对你有用,请随意赞赏 ×Close 赞赏作者 扫一扫支付 支付宝支付 微信支付