大家好,我是 android 新手,想在这里显示二次公式计算是我在 android 中执行的代码,此代码中没有显示错误,但仍然在模拟器上它不显示结果:-(
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b1 = (Button) findViewById(R.id.btnSubmit);
final EditText et1 = (EditText) findViewById(R.id.etVA);//whats wrong
final EditText et2 = (EditText) findViewById(R.id.etVC);//whats wrong
final EditText et3 = (EditText) findViewById(R.id.etVC);//whats wrong
final TextView answer = (TextView) findViewById(R.id.txtResult);//whats wrong
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String a1 = et1.getText().toString();//whats wrong
double a = Double.parseDouble(a1);//whats wrong
String b1 = et2.getText().toString();//whats wrong
double b = Double.parseDouble(b1);//whats wrong
String c1 = et3.getText().toString();//whats wrong
double c = Double.parseDouble(c1);//whats wrong
double x1 = (-b+Math.sqrt(b*b-4*a*c))/(2*a);//whats wrong
System.out.println("x1 = "+ x1);
String R = x1+ ""; //whats wrong
answer.setText("Your Answer is " + R); //whats wrong
}
});
}