I'm trying to create a calculator for one of my first projects in java. I ask the user for two number inputs and a symbol to choose the operation. It asks for the inputs then stops once it reaches the if statements to calculate the answer.
import java.util.Scanner;
class Calculator{
public static void main(String args[]){
double a;
double b;
double answer;
String symbol;
Scanner in = new Scanner(System.in);
System.out.print("Enter an operation");
symbol = in.nextLine();
System.out.print("Enter the first number");
a = in.nextInt();
System.out.print("Enter the second number");
b = in.nextInt();
if (symbol == "+"){
answer = a+b;
System.out.print(answer);
}
else if (symbol == "-"){
answer = a-b;
System.out.print(answer);
}
else if (symbol == "/"){
answer = a/b;
System.out.print(answer);
}
else if (symbol == "*"){
answer = a*b;
System.out.print(answer);
}
}
}
Here is my output
Enter an operation +
Enter the first number 4
Enter the second number 5