java - How to check if an input answer to a randomly generated mathematical equation is correct -


i have java program generates 2 random numbers , asks user mathematical operator , uses 3 elements ask user equation. trying check if answer user inputs correct , display either correct or incorrect.

randomgenerator rand = new randomgenerator(); x=rand.nextint(-10,10); y=rand.nextint(-10,10);  op=readline("choose operator (+, -, /, or *): ");  equ = x + op + y + "= ";  val = readint(equ);  z = x + op + y  if(z == val) {      println("correct!!");  }  if(z != val) {      println("incorrect.");  } 

the number of operators limited may want have switch cases each operator , calculate values. example

case '+':   value = + b;  case '-':  string value = + b; 

Comments