gpt4 book ai didi

java - 如何使用 math.random 类生成随机整数

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:08:19 24 4
gpt4 key购买 nike

<分区>

我在使用 RandInt() 方法时遇到问题,因为它不会返回随机整数。结果必须是 int 范围 0-9 并且必须使用 math.random 类。这是我的代码:

public class RandNumGenerator {
public static int RandInt() {
int n = (int) Math.random() * 10;
return n;
}
public static void main(String[] args) {
RandInt();
}
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com