Java - 解析简单计算器程序的字符串的问题
我有代码需要输入,然后计算出你想要用它做什么
例如。你会输入“x(+, - ,.. etc)y”,它会为你计算它。
即时通讯目前使用扫描仪和分裂它使得
double x = input.nextDouble();
String z = input.next();
double y = input.nextDouble();
现在我遇到了一个问题。说我想做一个阶乘,我会输入“x!”但代码仍然需要最后一次input.nextDouble();
我该怎么去(使用我在做的事情,如果可能的话)检查是否所有3都有输入,然后在使用if语句的方法之间进行选择,或者只有2个输入。
相对码
System.out.print("> ");
double x = input.nextInt();
String z = input.next();
double y = input.nextInt();
if (x == 0) {
running = false;
} else if (z.equalsIgnoreCase("+")) {
System.out.println(addition(x, y));
}