gpt4 book ai didi

Java长度方法错误

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

我正在开发一个听写程序,在该程序中我尝试将学生输入的文本与正确的文本进行比较,但编译时出现错误,这对我来说没有意义。

代码:

String[] list_answer = exercise_english_1.answer.split("\\s+");
String[] list_responce = exercise_english_1.response.split("\\s+");
ArrayList<String> list_error = new ArrayList<String>();

for(int i = 0; i < list_answer.length(); ++i) {
if (list_responce[i].equals(list_answer[i]))
exercise_english_1_statistics.score += (double) 1 / list_answer.length();
else
list_error.add(list_responce[i]);
}

错误:

C:\Users\?????\OneDrive\Java\Project\Prototype\Prototype.java:71: error: cannot find symbol
for(int i = 0; i < list_answer.length(); ++i) {
^
symbol: method length()
location: variable list_answer of type String[]
C:\Users\?????\OneDrive\Java\Project\Prototype\Prototype.java:73: error: cannot find symbol
exercise_english_1_statistics.score += (double) 1 / list_answer.length();

symbol: method length()
location: variable list_answer of type String[]
C:\Users\?????\OneDrive\Java\Project\Prototype\Prototype.java:208: error: cannot find symbol
for(int i = 0; i < list_answer.length(); ++i) {
^
symbol: method length()
location: variable list_answer of type String[]
C:\Users\?????\OneDrive\Java\Project\Prototype\Prototype.java:210: error: cannot find symbol
exercise_french_1_statistics.score += (double) 1 / list_answer.length();
^
symbol: method length()
location: variable list_answer of type String[]
4 errors

PS:抱歉我的英语不好,这不是我的母语......

最佳答案

数组没有 length() 方法,它们有一个 length 公共(public)成员:

for(int i = 0; i < list_answer.length; ++i) {
// Here (note: no ()) -----^

关于Java长度方法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37768426/

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