title: Generate random math operator in Java
body: <p>I was wondering how I should initialize int c from the switch statement. I can't figure out how to "extract" the random switch-argument into the final answer. I am a beginner so maybe I am missing something obvious here. Here is the code that I have so far:</p>
  
  <pre><code>import java.util.*;
  public class whileTest{
  public static void main (String args[]){
      Scanner sc = new Scanner(System.in);
  
      String a;
  
          do{
  
          String operatorSwitch;
          int b;
          int c;
  
          Random number = new Random();
          int d = number.nextInt(100) +1;
          int e = number.nextInt(100) +1;
  
          Random operatorChoice = new Random();
          int operator = operatorChoice.nextInt(4);
  
          switch (operator){
  
              case 0: operatorSwitch= "+";
                  c = d+e;
                  break;
              case 1: operatorSwitch= "-";
                  c = d-e;
                  break;
              case 2: operatorSwitch= "*";
                  c = d*e;
                  break;
              case 3: operatorSwitch= "/";
                  c = d/e;
                  break;
              default: operatorSwitch= "";
          }
          System.out.println("What is: "+d+operatorSwitch+e+"?");
          b = sc.nextInt();
  
  
          if(b!=c)
              System.out.println("Wrong answer! Right answer is: "+c);
          else{if(b==c)
              System.out.println("Right answer!"+c);
          }
              System.out.println("Continue? y/n");
              a = sc.next();
  
          }while(a.equals("y"));
      }
  }
  </code></pre>