# Problem with detecting Math operation.

• August 4th, 2012, 09:13 AM
BleedObsidian
Problem with detecting Math operation.
Hello,

I am having trouble testing to see what Mathematica operator the user has in-putted.

Here is the function (There are others so don't worry that this wouldn't actually run)

Code :

```public static void calc() { Scanner calcinputS = new Scanner(System.in); String calcinput, op; int answer, fnum, snum;   System.out.println("-------------------------"); System.out.println("| Calculator v1.0 |"); System.out.println("-------------------------"); System.out.print(" Enter an equation: "); calcinput = calcinputS.nextLine();   String[] calcinputA = calcinput.split(" "); fnum = Integer.parseInt(calcinputA[0]); op = calcinputA[1]; snum = Integer.parseInt(calcinputA[2]);   if (op == "+") { answer = fnum + snum; System.out.println(answer); } else if (op == "-") { answer = fnum - snum; System.out.println(answer); } else if (op == "*") { answer = fnum * snum; System.out.println(answer); } else if (op == "/") { answer = fnum / snum; System.out.println(answer); } else { System.out.println("Error: Could not recognize operation: " + op); }   }```

Thank you
• August 4th, 2012, 10:00 AM
Norm
Re: Problem with detecting Math operation.
You should use the equals() method for comparing Strings, not the == operator.
• August 4th, 2012, 10:04 AM
BleedObsidian
Re: Problem with detecting Math operation.
Ah, Thank you.