After this problem is fixed, my math game will run. The answer variable is supposed to be equal to the cases in the second switch statement by random but I get errors whenever I try to initialize it this way. I have been writing this program for almost 5 days now and it is finally wrapping up. Does anyone know why I can't map the answer variable to the second switch statement the way I want to?
package pkgnew; import java.util.Scanner; import java.util.Random; public class New { public static void main(String args[]) { //Declare and construct variables Random randomnum = new Random(); int fnum, snum, answer; int mathnumber = randomnum.nextInt(20); int newnumber = randomnum.nextInt(20); //Declare and construct variables of math problem fnum = mathnumber; snum = newnumber; //Declare random operator variable String[] operators = {"+" , "-", "*", "/" }; int randomIndex = randomnum.nextInt(3); String symbol = operators[randomIndex]; //Switch statement for random operator and question display switch (symbol) { case "+": System.out.println(fnum + "+" + snum); break; case "-": System.out.println(fnum + "-" + snum); break; case "*": System.out.println(fnum + "*" + snum); break; case "/": System.out.println(fnum + "/" + snum); break; } //Declare random answer variable String[] solutions = {fnum + "+"+ snum, fnum + "-" + snum, fnum + "*" + snum, fnum + "/" + snum }; int randomCase = randomnum.nextInt(3); String userInput = solutions[randomCase]; //Switch statement to map answer to question display switch (userInput) { case "fnum + \"+\"+ snum": answer = fnum + snum; break; case "fnum + \"-\" + snum": answer = fnum - snum; break; case "fnum + \"*\" + snum": answer = fnum * snum; break; case "fnum + \"/\" + snum": answer = fnum / snum; break; } //User input Scanner serena = new Scanner(System.in); int userAnswer = serena.nextInt(); //If user input = answer display "correct" if (userAnswer == answer) { System.out.println("Correct!"); //If user input does not = answer display "wrong" and correct answer } else { System.out.print("Wrong! The correct answer is: "); System.out.print(answer); } } }