views:

245

answers:

2

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++;
                        }
                    }
                }
            }
        }
    }
}
+2  A: 

You are missing a closing curly-brace (}) for your main function - place one before the countIndex function declaration. You will also need to call countIndex from main, I presume (edit: elaborated...)

flatline
+5  A: 

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

Greg Hewgill