嗨,我在用 java 制作测验程序时遇到问题,这是我所拥有的:(注意:我没有为 Q3-10 设置问题)。我遇到的问题是一旦用户正确输入第一个问题,并显示第二个问题,如果用户输入第二个问题的正确答案:a^2+b^2=c^2,那么“对不起,你输了,你的分数是 1/10 仍然显示”。即使它应该是:“正确!下一个问题:”我刚刚开始编码,如果这是一个简单的错误,我很抱歉。
import java.util.Scanner;
public class Quiz {
public static void main(String[] args) {
int Q1 = 0, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10 = 0;
String Q2 = "";
Scanner in = new Scanner(System.in);
Scanner st = new Scanner(System.in);
System.out.println("Welcome to the math quiz!, Type Reset at any time to start over");
System.out.println("Q1: What is the square root of 9?");
//beggining of questions:
while (Q1 != 3) {
Q1 = in.nextInt();
if ( Q1 == 3) {
System.out.println("Correct! Next Question:");
System.out.println("Q2: What is pythagreoum's therom?");
} else {
System.out.println("Sorry, you lost, your score is 0/10");
}
}
//end of Q1
while (Q2 != "a^2+b^2=c^2" ) {
Q2 = st.nextLine();
if ( Q2 == "a^2+b^2=c^2" ) {
System.out.println("Correct! Next Question:");
}
else {
System.out.println("Sorry, you lost, your score is 1/10");
}
}
//end of Q2
}
}