Hey guys! I'm working on a console calculator. My problem is that how would I perform the inputted operator? So, if the user inputs "+" and a "-" it will perform those. Here's what I have so far:
import java.util.Scanner;
public class Calculator
{
public static void main (String []args)
{
Scanner in = new Scanner (System.in);
int firstInput;
int secondInput;
int thirdInput;
String firstOperator;
String secondOperator;
int result;
System.out.print ("1st input: ");
firstInput = in.nextInt();
System.out.print ("1st Operator: ");
firstOperator = in.next();
System.out.print ("2nd input: ");
secondInput = in.nextInt();
System.out.print ("2nd Operator: ");
secondOperator = in.next();
System.out.print ("3rd input: ");
thirdInput = in.nextInt();
if (firstOperator == "+" && secondOperator == "+" )
{
result = firstInput + secondInput + thirdInput;
System.out.println ("The Expression: "+firstInput+firstOperator+secondInput+secondOperator+thirdInput);
System.out.println ("The Result is: " +result);
}
}
}