gpt4 book ai didi

java - 对于安全随机类型,方法 nextInt 未定义

转载 作者:行者123 更新时间:2023-12-02 20:46:30 26 4
gpt4 key购买 nike

我尝试使用此代码生成随机数,但不断收到此错误

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
The method nextInt(int) is undefined for the type SecureRandom

at SecureRandom.main(SecureRandom.java:18)

这是我尝试过的

public class SecureRandom {

public static void main(String[] args) {
SecureRandom randomNumbers = new SecureRandom();
for (int count = 1; count <=20; count++) {

int face = 1+randomNumbers.nextInt(6);
System.out.printf( " %d" , face);

if (count %5 ==0) {
System.out.println();
}

}

}

}

最佳答案

编译器正在根据您定义的类解析SecureRandom。您应该更改类名以避免与 java.security.SecureRandom 冲突。

关于java - 对于安全随机类型,方法 nextInt 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27341859/

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