Hi I am having issues making a quiz program in java, here is what I have: (note: I have not set questions for Q3-10). The issue I am having is once the user enters the first question correctly, and the second question is displayed, if the user enters in the correct answer for the second question: a^2+b^2=c^2, then "Sorry, you lost, your score is 1/10 is still displayed". Even though it is supposed to be: "Correct! Next Question:" I have just started coding so sorry if this a easy mistake.
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
}
}