这个程序应该是一个基本的计算器,它接受两个双输入,然后提示用户使用相应的数学运算符键入一个字符串。由于某种原因,在用户输入与菜单对应的字符串后,我的基本计算器不会返回值。
import java.util.Scanner;
public class Assignment3 {
public static void main (String[] args)
{
String operator = "";
double userInputOne;
double userInputTwo;
double output = -.00001;
String comparison = "";
Scanner scan = new Scanner(System.in);
System.out.println("Enter the first number of your calculation:");
userInputOne = scan.nextDouble();
System.out.println("Enter the second number of your calculation:");
userInputTwo = scan.nextDouble();
System.out.println("Type in one direction under Calculator Options:");
System.out.println("Add, Subtract, Multiply, Divide, Mod");
System.out.println("Compare");
System.out.println("Print Numbers");
System.out.println("Quit");
Scanner scanTwo = new Scanner(System.in);
operator = scanTwo.nextLine();
if (operator == "Add")
{
output = userInputOne + userInputTwo;
}else if (operator == "Subtract"){
output = userInputOne - userInputTwo;
}else if (operator == "Multiply"){
output = userInputOne * userInputTwo;
}else if (operator == "Divide"){
output = userInputOne / userInputTwo;
}else if (operator == "Mod"){
output = userInputOne % userInputTwo;
}else if (operator == "Compare"){
if(userInputOne == userInputTwo){
comparison = (userInputOne + " Is equal to " + userInputTwo);
System.out.println(comparison);
}else if (userInputOne > userInputTwo){
comparison = (userInputOne + " Is greater than " + userInputTwo);
System.out.println(comparison);
}else if (userInputOne < userInputTwo){
comparison = (userInputOne + " Is less than " + userInputTwo);
System.out.println(comparison);
}
}else if (operator == "Print Numbers"){
comparison = userInputOne + " " + userInputTwo;
System.out.println(comparison);
}else if (operator == "Quit"){
System.exit(0);
}
if (output != -.00001){
System.out.println(output);
}
}
}