问题是微不足道的,但我在这里遗漏了一些非常基本的东西,无法捕捉到它.请帮忙.我正在编写一个简单的计算器程序,可以在命令行中使用.源代码如下.问题是当我使用计算器时
>java SwitchCalc 12 * 5
Run Code Online (Sandbox Code Playgroud)
它为args [2]解析第二个int的语句中的输入字符串抛出'java.lang.NumberFormatException':"002.java":
int value2 = Integer.parseInt(args[2])
Run Code Online (Sandbox Code Playgroud)
后来我尝试了以下,它的工作原理.
>java SwitchCalc 12 "*" 5
12 * 5 = 60
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
/*
User will input the expression from command-line in the form:
>java SwitchCalc value1 op value2
where,
value1, and value2 are integer values
op is an operator in +, -, *, /, %
Program will evaluate the expression and will print the result. For eg.
>java SwitchCalc 13 % 5
3
*/
class SwitchCalc{
public static …Run Code Online (Sandbox Code Playgroud) java string input command-line-arguments numberformatexception