我的计算器应用中存在问题
我尝试调用方法,但是当我这样做时,我的应用程序崩溃了
我使用int
和double
使用相同的方法,但double
崩溃(是同一个调用)
public void pressEquals(View v)
{
String[] tar = tvResult.getText().toString().split(" ");
String res = " ";
double dRes = Double.valueOf(tar[0])+Double.valueOf(tar[2]);
int iRes = Integer.valueOf(tar[0])+Integer.valueOf(tar[2]);
if ( dRes == iRes)
intcalc(iRes, tar);
else
doublecalc(dRes, tar);
}
public void intcalc(int num, String [] tar)
{
int result = num;
String res = " ";
if(tar[1].equals("+"))
res = tar[0] + " + " + tar[2] + " = " + result;
else if(tar[1].equals("-"))
res = tar[0] + " - " + tar[2] + " = " + result;
else if(tar[1].equals("*"))
res = tar[0] + " * " + tar[2] + " = " + result;
else if(tar[1].equals("/"))
res = tar[0] + " / " + tar[2] + " = " + result;
tvResult.setText(res);
}
public void doublecalc(double num, String [] tar)
{
double result = num;
String res = " ";
if(tar[1].equals("+"))
res = tar[0] + " + " + tar[2] + " = " + result;
else if(tar[1].equals("-"))
res = tar[0] + " - " + tar[2] + " = " + result;
else if(tar[1].equals("*"))
res = tar[0] + " * " + tar[2] + " = " + result;
else if(tar[1].equals("/"))
res = tar[0] + " / " + tar[2] + " = " + result;
tvResult.setText(res);
}