title: Storing string and double values from a single line
body: <pre class="lang-java prettyprint-override"><code>import java.util.Scanner;
  
  public class a2q1 {
  
          public static void main(String[] args) {
              double reg = 0;
              double heap[];
              heap = new double[5];
              boolean end = false;
  
              Scanner in = new Scanner(System.in);
              while (!end) {
                  System.out.println(&quot;Enter the Command: &quot;);
                  String cmd = in.next();
                  double v = in.nextInt();
                  if (cmd.equalsIgnoreCase(&quot;SET&quot;)){
                      reg = v;
                  }
                  if (cmd.equalsIgnoreCase(&quot;TELL&quot;)) {
                      System.out.print(reg);
                  }
                  if (cmd.equalsIgnoreCase(&quot;ADD&quot;)){
                      reg = reg + v;
                  }
                  if (cmd.equalsIgnoreCase(&quot;SUB&quot;)) {
                      reg = reg - v;
                  }
                  if (cmd.equalsIgnoreCase(&quot;MUL&quot;)) {
                      reg = reg * v;
                  }
                  if (cmd.equalsIgnoreCase(&quot;DIV&quot;)) {
                      reg = reg / v;
                  }
                  if (cmd.equalsIgnoreCase(&quot;HALT&quot;)) {
                      end = true;
                      System.exit(0);
                  }
              }
          }
  }
  </code></pre>
  <p>In this code, I am trying to read some commands from the user and do the arithmetic accordingly. commands will look like, 'Add 1' which should add 1 to the register, 'Mul 2' will multiply, 'SET 10' will set the value of the register to 10, 'HALT&quot; will terminate the program and 'TELL&quot; will print the current register value.
  Although my loop seems to work fine,I think I might be having some problems with storing those string and the number (double). Any suggestions to correct this mistake? Any help is appreciated.    (Ignore the heap array)</p>
  <p>Following is the exception it is throwing</p>
  <pre><code>&gt; Exception in thread &quot;main&quot; java.util.InputMismatchException   at
  &gt; java.base/java.util.Scanner.throwFor(Scanner.java:943)    at
  &gt; java.base/java.util.Scanner.next(Scanner.java:1598)   at
  &gt; java.base/java.util.Scanner.nextInt(Scanner.java:2263)    at
  &gt; java.base/java.util.Scanner.nextInt(Scanner.java:2217)    at
  &gt; a2q1.main(a2q1.java:15)
  </code></pre>