【发布时间】:2009-10-12 00:10:28
【问题描述】:
/*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");
}
}
}
这是我正在编写的程序。我想制作一个计数器来记录每个正确回答的问题,然后在问题完成后将其显示给用户。我试过用这个:
int score=0;
score=score+1;
它不适用于第二个问题,但适用于第三个问题......它给了我一个错误。 还有其他方法可以做到这一点还是我做错了什么?
【问题讨论】:
-
嘿,非常感谢,我尝试增加它,但我输入的代码错误,所以我一直收到错误,但现在应该可以工作了
-
啊,不,它说它不起作用文件:K:\Quiz\Quiz.java [行:29] 错误:K:\Quiz\Quiz.java:29:表达式的非法开始请帮助
-
您需要在语句的末尾包含分号。