在这里插入代码片
```public class GetMax {
public static void getmax() {
Random r=new Random();//引用Random方法获取随机数
Scanner sc=new Scanner(System.in);
int a=r.nextInt(100)+1;//规定随机数范围1--100
int b=r.nextInt(100)+1;
if(a>b) {
System.out.println(a+"大于"+b);
}else if(a<b) {
System.out.println(a+"小于"+b);
}else {
System.out.println("a b 一样大");
}
}
}
//下面为测试类
public static void main(String[] args) {
// TODO 自动生成的方法存根
GetMax gg=new GetMax();//创建对象
gg.getmax();//调用方法
}
}
【无标题】2022年12月24日 使用Random 进行判断两个随机数的大小
最新推荐文章于 2024-07-29 18:00:00 发布