/*This is a quiz program that will ask the user 10 questions. the user will answer
* these questions and will be scored out of 10.*/
class Quiz {
public static void main(String args[]) {
// Instructions
System.out.println("instructions");
System.out.println(" ");
System.out
.println("1. You wll be asked ten questions through out the quiz.");
System.out
.println("2. The first question will appear, you will have to answer that question for the next question to appear.");
System.out
.println("3. When you answer the last question you will be told your score.");
System.out.println(" ");
System.out.println("welcome to the basketball quiz.");
// question 1
System.out.println(" ");
System.out.println("Question 1. ");
System.out.println("How tall is a basketball hoop? ");
System.out.println("Type in Answer here:");
String Question1 = In.getString();
if (Question1.equalsIgnoreCase("10 Feet")) {
System.out.println("Correct!");
} else {
System.out.println("you got this questions wrong");
}
// question 2
System.out.println(" ");
System.out.println("Question 2. ");
System.out.println("Who invented basketball? ");
System.out.println("Type in Answer here:");
String Question2 = In.getString();
if (Question2.equalsIgnoreCase("James Naismith ")) {
System.out.println("Correct!");
} else {
System.out.println("you got this questions wrong");
}
}
}
Ceci est mon programme que j'écris. Je veux faire un compteur qui gardera le score de chaque question qui répond à droite et ensuite l'afficher à l'utilisateur après que les questions sont terminées. J'ai essayé d'utiliser ceci:comment créer un compteur dans un programme dr Java
int score=0;
score=score+1;
Il ne fonctionne pas pour la 2ème question, mais travaille pour le 3ème ... il me donne une erreur. Existe-t-il une autre façon de faire cela ou est-ce que je fais quelque chose de mal?
hey merci beaucoup j'ai essayé de l'incrémenter mais je tapais le code erroné donc c'est yi gardé une erreur est devrait fonctionner maintenant si –
ahh nop il fonctionne dousnt il dit Fichier: K: \ Quiz \ Quiz.java [ligne : 29] Erreur: K: \ Quiz \ Quiz.java: 29: début d'expression illégal aidez s'il vous plaît –
Vous devez inclure des points-virgules à la fin de vos instructions. – akf