如何修复“非法开始表达”? Java中的错误? [英] How do I fix an "Illegal start of expression" error in Java?

查看:129
本文介绍了如何修复“非法开始表达”? Java中的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在注释标记的位置的以下代码中收到非法表达式启动错误。如何更正此错误?

I am getting an "Illegal start of expression" error in the following code at the location marked by a comment. How can I correct this error?

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中将方法嵌套在另一个中。在 main()方法之外移动 countIndex()

You can't nest methods within one another in Java. Move countIndex() outside the main() method.

这篇关于如何修复“非法开始表达”? Java中的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆