所以在我的應用程序中有這部分使用二次公式來解決總和。但我得到一個奇怪的輸出。這是我所得到的,而不是實際的答案,「NaN或NaN」奇怪的Math.sqrt輸出()在android
此代碼在單擊按鈕上執行。
h1 = Double.parseDouble(a);
h2 = Double.parseDouble(b);
h3 = Double.parseDouble(c);
sq2 = (h1 * h1 - 4* 0.5 *h3*h1);
sq = (h1 * h1 - 4* 0.5 *h3*h1);
fin = h1 + (Math.sqrt(sq2))/(2* 0.5 * h3);
fin2 = (h1 - (Math.sqrt(sq)))/(2* 0.5 * h3);
AlertDialog.Builder ans4 = new AlertDialog.Builder(Eq2.this);
ans4.setTitle("ANSWER");
ans4.setMessage(fin + " or " + fin2);
ans4.setPositiveButton("OKAY!", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
e4.setText(fin + "or" + fin2);
}
});
ans4.show();
檢查'h1> = 2 * h3'。如果不是,你得到一個負數。 (無論如何,h2是什麼?) – usr2564301