Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我如何修复一个";“表达式开头非法”;Java中的错误?_Java - Fatal编程技术网

我如何修复一个";“表达式开头非法”;Java中的错误?

我如何修复一个";“表达式开头非法”;Java中的错误?,java,Java,在下面的代码中,我在注释标记的位置发现了一个“表达式的非法开始”错误。如何更正此错误 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'

在下面的代码中,我在注释标记的位置发现了一个“表达式的非法开始”错误。如何更正此错误

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++;
                        }
                    }
                }
            }
        }
    }
}
类平面图{
公共静态void main(字符串[]args){
//有计算索引的数据
字符字母[]={'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';
//初始数据
字符串[]组={“COMETQ”,“Abstrar”};
字符串[]comets={“HVNGAT”,“USACO”};
//这里有问题!
//数一数索引
私有void countIndex(字符串组,字符串comet){
//我在这里看到“表达式的非法开始”
//在数组中有两个单词
char[]name={group,comet};
//在数组块中逐个遍历单词
int k=0;
for(int k:name[k]){
//将每个字母保存到数组中
char[]words=name[k].toCharArray();
整数和=1;
//循环遍历单词中的每个字符
for(int i=0;i
您的主函数缺少一个右大括号(}),请将其放在countIndex函数声明之前。您还需要从main调用countIndex,我想(edit:detained…

您不能在Java中将方法嵌套在另一个方法中。将
countIndex()
移到
main()方法之外