gpt4 book ai didi

java - 如何修复 Java 中的 "Illegal start of expression"错误?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:43:49 27 4
gpt4 key购买 nike

我在以下代码中注释标记的位置收到“表达式的非法开始”错误。我该如何纠正这个错误?

class planetUfo {
public static void main (String[] args) {
// having data for counting the index
char letters[] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

// initial data
String[] groups = {"COMETQ", "ABSTAR"};
String[] comets = {"HVNGAT", "USACO"};


// Problem here!
// to count the index
private void countIndex ( String group, String comet ) {
// I get here "illegal start of an expression"



// to have two words in the array
char[] name = { group, comet };
// to go though the words one by one in the block of the array
int k = 0;
for ( int k : name[k] ) {
// to save each letter to an array
char[] words = name[k].toCharArray();

int sum = 1;
// to loop through each character in the word
for ( int i = 0; i < words.length; i++) {
// to loop through each necessary character in the alphabets
int j = 0;
for ( int j = 0; j < letters.length; j++ ) {
while ( letters[j] !== words[i] ) {
// to look the index of the letter in the word
int indexNumber = j;
sum = sum * (indexNumber + 1);
index[k] = sum;
j++;
}
}
}
}
}
}
}

最佳答案

在 Java 中,您不能将方法相互嵌套。将 countIndex() 移到 main() 方法之外。

关于java - 如何修复 Java 中的 "Illegal start of expression"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1534263/

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