Bonjour Madame, Monsieur,
Je suis novice java. Je suis entrait d'apprendre Java. J'essaie de comprendre un tutoriel. Mais je n'arrive pas trouver la solution.
J'ai déjà changé le nom de dossier mais rien ne change . J'ai essayé aussi un nouveau fichier pour chaque classe. Pouvez-vous me dire ou se trouve ma faute?.
Je remercie d'avance.
Voici les erreurs émis :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 public class SimpleDotComTestDrive{ public static void main (String [] args){ SimpleDotCom dot = new SimpleDotCom(); int[] locations = {2,3,4}; dot.setLocationCells(location); String userGuess ="2"; String result = dot.checkYourself(userGuess); } } public class SimpleDotCom{ int [] locationCells; int numofHits = 0; public void setLocationCells(int [] locs){ locationCells = locs; } public String checkYourself( String stringGuess){ int guess = Integer.parseInt(stringGuess); String result = "miss"; for (int cell : locationCells){ if (guess == cell){ result = "hit"; numOfHits ++; break ; } } if (numOfHits == locationCells.lenght){ result = "kill"; } System.out.println(result); return result; } }
Code console : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 javac SimpleDotComGame.java SimpleDotComGame.java:1: error: class SimpleDotComTestDrive is public, should be declared in a file named SimpleDotComTestDrive.java public class SimpleDotComTestDrive{ ^ SimpleDotComGame.java:9: error: cannot find symbol dot.setLocationCells(location); ^ symbol: variable location location: class SimpleDotComTestDrive ./SimpleDotCom.java:19: error: cannot find symbol numOfHits ++; ^ symbol: variable numOfHits location: class SimpleDotCom ./SimpleDotCom.java:24: error: cannot find symbol if (numOfHits == locationCells.lenght){ ^ symbol: variable numOfHits location: class SimpleDotCom ./SimpleDotCom.java:24: error: cannot find symbol if (numOfHits == locationCells.lenght){ ^ symbol: variable lenght location: variable locationCells of type int[] 5 errors
Partager