我应该制作一个输入三个参数的程序,这些参数稍后将被计算。第一个和第三个参数是字符串格式的数字(例如“three”),而第二个参数是操作(例如“-”“+”)。一切正常,除非我使用“*”操作。我试图在它通过解析器函数时打印字符串,因为这是发生错误的地方,它打印“.project”而不是字符串格式的数字。
static int converter(String x)
{
System.out.println(x);
int value = 0;
String zero = "0";
String one = "1";
String two = "2";
String three = "3";
String four = "4";
String five = "5";
String six = "6";
String seven = "7";
String eight = "8";
String nine = "9";
String ten = "10";
String eleven = "11";
String twelve = "12";
String thirteen = "13";
String fourteen = "14";
String fifteen = "15";
String sixteen = "16";
String seventeen = "17";
String eighteen = "18";
String nineteen = "19";
String twenty = "20";
String thirty = "30";
String forty = "40";
String fifty = "50";
String sixty = "60";
String seventy = "70";
String eighty = "80";
String ninety = "90";
if(x.compareTo("zero")==0)
value = Integer.parseInt(zero);
else if(x.compareTo("one")==0)
value = Integer.parseInt(one);
else if(x.compareTo("two")==0)
value = Integer.parseInt(two);
else if(x.compareTo("three")==0)
value = Integer.parseInt(three);
else if(x.compareTo("four")==0)
value = Integer.parseInt(four);
else if(x.compareTo("five")==0)
value = Integer.parseInt(five);
else if(x.compareTo("six")==0)
value = Integer.parseInt(six);
else if(x.compareTo("seven")==0)
value = Integer.parseInt(seven);
else if(x.compareTo("eight")==0)
value = Integer.parseInt(eight);
else if(x.compareTo("nine")==0)
value = Integer.parseInt(nine);
else if(x.compareTo("ten")==0)
value = Integer.parseInt(ten);
else if(x.compareTo("eleven")==0)
value = Integer.parseInt(eleven);
else if(x.compareTo("twelve")==0)
value = Integer.parseInt(twelve);
else if(x.compareTo("thirteen")==0)
value = Integer.parseInt(thirteen);
else if(x.compareTo("fourteen")==0)
value = Integer.parseInt(fourteen);
else if(x.compareTo("fifteen")==0)
value = Integer.parseInt(fifteen);
else if(x.compareTo("sixteen")==0)
value = Integer.parseInt(sixteen);
else if(x.compareTo("seventeen")==0)
value = Integer.parseInt(seventeen);
else if(x.compareTo("eighteen")==0)
value = Integer.parseInt(eighteen);
else if(x.compareTo("nineteen")==0)
value = Integer.parseInt(nineteen);
else if(x.compareTo("twenty")==0)
value = Integer.parseInt(twenty);
else if(x.compareTo("thirty")==0)
value = Integer.parseInt(thirty);
else if(x.compareTo("forty")==0)
value = Integer.parseInt(forty);
else if(x.compareTo("fifty")==0)
value = Integer.parseInt(fifty);
else if(x.compareTo("sixty")==0)
value = Integer.parseInt(sixty);
else if(x.compareTo("seventy")==0)
value = Integer.parseInt(seventy);
else if(x.compareTo("eighty")==0)
value = Integer.parseInt(eighty);
else if(x.compareTo("ninety")==0)
value = Integer.parseInt(ninety);
else {
System.out.println("Error.");
System.exit(0);
}
return value;
}
如果我输入“*”而不是“*”,程序运行正常。