gpt4 book ai didi

java - 错误: Cannot find symbol showing up Java Beginner

转载 作者:行者123 更新时间:2023-12-01 18:34:18 24 4
gpt4 key购买 nike

我正在尝试创建一个程序,从文件中选择一个随机单词,并根据单词的长度输出正确的空格数。例如,如果单词是 smart,则程序输出 _ _ _ _ _。这是程序:

    import java.util.*;
import java.io.*;
public class Selection {
public static void main(String[] args) throws IOException {
String[] words = new String[100];
Scanner in = new Scanner(new FileReader("words.txt"));
for (int i = 0; i < 100; i++)
words[i] = in.next();
Random r = new Random();
int selected = r.nextInt[100];
String sWord = words[selected];

for (int j = 0; j < sWord.length(); j++)
System.out.printf("_");

in.close();
}
}

这是错误:

    java:18: error: cannot find symbol
int selected = r.nextInt[100];
^
symbol: variable nextInt
location: variable r of type Random
1 error

任何帮助理解我没有做正确的事情的帮助将不胜感激。

最佳答案

 int selected = r.nextInt[100];// use () r.nextInt(num);

关于java - 错误: Cannot find symbol showing up Java Beginner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22747680/

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