/*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;
它不适用于第二个问题,但适用于第三个问题......它给了我一个错误。
我还有其他方法可以做到这一点还是我做错了什么?
看来您走在正确的轨道上。您需要在程序开头声明一个分数变量。
int score = 0;
然后,在打印出“正确”的每个问题中,您可以像这样增加分数:
score++;
在程序结束时,在最后一个问题之后,您可以打印分数。
也许您应该发布尝试时遇到的错误。
UPDATE:语法是score++ 而不是score=++。即去掉=号。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)