Comment puis-je corriger “Illégal début de l'expression” erreur en Java?
Je reçois un "Illégal début de l'expression" erreur dans le code suivant à l'endroit marqué par un commentaire. Comment puis-je corriger cette erreur?
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++;
}
}
}
}
}
}
}
OriginalL'auteur Léo Léopold Hertz 준영 | 2009-10-07
Vous devez vous connecter pour publier un commentaire.
Vous ne pouvez pas imbriquer les méthodes à l'intérieur de l'un à l'autre en Java. Déplacer
countIndex()
à l'extérieur de lamain()
méthode.OriginalL'auteur Greg Hewgill
Il vous manque une fermeture bouclés-brace (}) votre fonction principale place avant la countIndex déclaration de fonction. Vous aurez également besoin d'appeler countIndex de main, je présume (edit: élaboré...)
OriginalL'auteur flatline