Been trying to make a simple calculator add, subtract, divide, multiply. But it is not allowing me to get to the calculation part. It always says "incorrect type of calculation" even when I type +,-,/, or '' How do I get the scanner to understand the +,-,/,'' as input? Thanks
import java.util.Scanner;
public class Calculator {
public void typeOfCalc(){
Scanner user_input = new Scanner(System.in);
System.out.print("What type of calculation do you want? \n Addition? type '+' \n Subtraction? type '-' \n Division? type '/' \n or Multiplication type '*' \n");
String calcType = user_input.next().trim();
if (calcType != "+" || calcType != "*" || calcType != "/" || calcType != "-"){
System.out.println("Incorrect type of calculation, try again \n");
typeOfCalc();
}
else if (calcType == "+"){
System.out.print("Chose your first number \n");
int num1 = user_input.nextInt();
System.out.print("Chose your second number \n");
int num2 = user_input.nextInt();
System.out.print(num1 + " + " + num2 + " = \n" + (num1 + num2) + "\n");
}
else if (calcType == "-"){
System.out.print("Chose your first number \n");
int num1 = user_input.nextInt();
System.out.print("Chose your second number \n");
int num2 = user_input.nextInt();
System.out.print(num1 + " - " + num2 + " = \n" + (num1 - num2) + "\n");
}
else if (calcType == "/"){
System.out.print("Chose your first number \n");
int num1 = user_input.nextInt();
System.out.print("Chose your second number \n");
int num2 = user_input.nextInt();
System.out.print(num1 + " / " + num2 + " = \n" + (num1 / num2) + "\n");
}
else if (calcType == "*"){
System.out.print("Chose your first number \n");
int num1 = user_input.nextInt();
System.out.print("Chose your second number \n");
int num2 = user_input.nextInt();
System.out.print(num1 + " * " + num2 + " = \n" + (num1 * num2) + "\n");
}
}
}