编写程序,实现猜数小游戏。随机生成一个0~99(包括0和99)的数字,从控制台输入猜测的数字,输出提示太大还是太小,继续猜测,直到猜到为止,游戏过程中,记录猜对所需的次数,游戏结束后公布结果。程序运行结果如图2所示。猜测次数与游戏结果对照见

205 2025-04-14 06:54

package hellomysql; import java.util.Random; import java.util.Scanner; public class hellosin { public static void main(String[] agrs){ int max=100; int min=1; Scanner shui=new Scanner(System.in); Random random = new Random(); int rd=random.nextInt(max)%(max-min+1) + min;; System.out.println(随机数:+rd); while(true){ int cmcc=shui.nextInt(); if(cmcc==rd){ System.out.println(正确); }else{ System.out.println(错误); } } } }

顶一下
(0)
0%
踩一下
(0)
0%
相关评论
我要评论
点击我更换图片