gpt4 book ai didi

java - 我从互联网复制的代码中收到错误

转载 作者:行者123 更新时间:2023-12-01 16:35:11 25 4
gpt4 key购买 nike

我从互联网上复制了一些代码:

    static Random randGen = new Random();     
int hit;
hit = randGen.nextInt(100) + 1;

我想要它做的是选择 1-100 之间的一个数字。但是,我在这段代码的第一行遇到错误:

Multiple markers at this line
-Random cannot be resolved into a type.
-Illegal modifier for parameter randGen; only final is permitted.
-Random cannot be resolved into a type.

最佳答案

  1. Random 无法解析为类型 - 您需要导入 Random(例如 import java.util.Random;)。
  2. 参数 randGen 的修改非法;仅允许使用final。 - 您不能在方法内使用static 修饰符。

关于java - 我从互联网复制的代码中收到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9972824/

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