Java 我想用我的两个输入做一个数学运算

Java 我想用我的两个输入做一个数学运算,java,android,string,double,Java,Android,String,Double,显示的答案总是0.0,我不知道我做错了什么。这是我的数据类型转换吗?您必须使用equals()方法来比较字符串标识。非==运算符 EditText txtDisplay = (EditText) findViewById(R.id.txtDisplay); display = txtDisplay.getText().toString(); operator = display.split("\\d|\\."); operand = display.split("\\+|

显示的答案总是0.0,我不知道我做错了什么。这是我的数据类型转换吗?

您必须使用
equals()
方法来比较字符串标识。非
==
运算符

EditText txtDisplay = (EditText) findViewById(R.id.txtDisplay);
    display = txtDisplay.getText().toString();
    operator = display.split("\\d|\\.");
    operand = display.split("\\+|\\-|\\*|\\/");

    if(operator[0] == "+"){
        answer = Double.valueOf(operand[0]) + Double.valueOf(operand[1]);
    }

    if(operator[0] == "-"){
        answer = Double.valueOf(operand[0]) - Double.valueOf(operand[1]);
    }

    if(operator[0] == "*"){
        answer = Double.valueOf(operand[0]) * Double.valueOf(operand[1]);
    }

    if(operator[0] == "/"){
        answer = Double.valueOf(operand[0]) / Double.valueOf(operand[1]);
    }

    txtDisplay.setText(String.valueOf(answer));

你调试代码了吗?如果输入了,我猜不会有
。您应该
Log.I
在引用sqlite以直接在一行中获得结果之前,先查看
运算符
操作数
的内容。只需传递用edittext编写的表达式。并得到结果
if(operator[0].equals("+")) {
    answer = Double.valueOf(operand[0]) + Double.valueOf(operand[1]);
}