Android计算器应用粉碎了

时间:2015-09-25 20:41:09

标签: android

我的计算器应用中存在问题 我尝试调用方法,但是当我这样做时,我的应用程序崩溃了 我使用intdouble使用相同的方法,但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);
}

0 个答案:

没有答案