0

As the title says, the program is terminating before the user input for the math operator can be input and immediately outputs the error message for an invalid input to the operator even though one was never entered.

code follows:

import java.util.Scanner; // Scanner for user input

public class asg2{

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);


System.out.println("Please, enter any two numbers separated by a space: ");
    double Input = scan.nextDouble();
    double Input2 = scan.nextDouble();

System.out.println("Next, please enter the mathematical operation symbol you wish these numbers to have performed on them: ");
    String Math = scan.nextLine();
    
double In1 = Input;
double In2 = Input2;
double out = 0;

    if (Math.equals("*")) {
    out = (In1 * In2);
    System.out.print("Evaluation: " +In1+ " * " +In2+" = " +out);
    }

    if (Math.equals("/")) {
    out = (In1 / In2);
    System.out.print("Evaluation: " +In1+ " / " +In2+" = " +out);
    }

    if (Math.equals("+")) {
    out = (In1 + In2);
    System.out.print("Evaluation: " +In1+ " + " +In2+" = " +out);
    }

    if (Math.equals("-")) {
    out = (In1 - In2);
    System.out.print("Evaluation: " +In1+ " - " +In2+" = " +out);
    }

    if (Math != ("*") || Math != ("-") || Math != ("/") || Math != ("+")) { 
    System.out.print("Evaluation: INVALID OPERATION SYMBOL");
    }
    
    
    

}

}

0 Answers0