Sqrt如何与BigDecimal一起工作?

时间:2015-01-01 17:49:05

标签: android eclipse math

我正在尝试在Android中设置平方根。我知道已经有很多关于此的问题,但我还没有弄清楚如何将答案纳入我的项目。我需要知道放入什么以及放在哪里。 (我更喜欢它尽可能简单,因为我对编程相对较新。)

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    final MediaPlayer buttonSound = MediaPlayer.create(Distance_Main.this,
            R.raw.button_sound);
    Intent i = new Intent(this, Distance_Keypad.class);
    switch (v.getId()) {
    case R.id.distance_x1:
        buttonSound.start();
        i.putExtra("numbers", "x1");
        startActivityForResult(i, 1);
        break;
    case R.id.distance_y1:
        buttonSound.start();
        i.putExtra("numbers", "y1");
        startActivityForResult(i, 1);
        break;
    case R.id.distance_x2:
        buttonSound.start();
        i.putExtra("numbers", "x2");
        startActivityForResult(i, 1);
        break;
    case R.id.distance_y2:
        buttonSound.start();
        i.putExtra("numbers", "y2");
        startActivityForResult(i, 1);
        break;
    case R.id.distance_calc:
        buttonSound.start();
        BigDecimal a = new BigDecimal(x1.getText().toString());
        BigDecimal b = new BigDecimal(y1.getText().toString());
        BigDecimal c = new BigDecimal(x2.getText().toString());
        BigDecimal d = new BigDecimal(y2.getText().toString());
        BigDecimal e = c.subtract(a);
        BigDecimal f = d.subtract(b);
        BigDecimal g = e.multiply(e);
        BigDecimal h = f.multiply(f);
        BigDecimal j = e.add(f);
        distance.setText("Distance = The Square Root of " + j + " Units");
        distance2.setText("Or " +  +" Units");
        break;
    default:
        break;
    }
}

0 个答案:

没有答案