所以我正在尝试测试一个基本的计算器,但程序在它要求“加法、减法、乘法或除法”之后立即结束——它没有给用户输入的机会。请帮助表示感谢:) 谢谢!
import java.util.Scanner;
public class Lator {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
float num1;
float num2;
String choice;
Scanner imput = new Scanner(System.in);
System.out.println("This is a calculator.");
System.out.println("Enter your first number.");
num1 = imput.nextFloat();
System.out.println("Enter your second number.");
num2 = imput.nextFloat();
System.out.println("Would you like to add, subtract, divide, or multiply?");
choice = imput.nextLine();
if(choice.equals("Add")||choice.equals("+")||choice.equals("Addition")) {
System.out.println("Number1 " + num1 + " + " + "number2" + num2 + "=" + (num1 + num2));
}
}
}