日期:2014-05-20 浏览次数:21320 次
/**Return the sqr**/
public Rational sqr(){
BigInteger temp1=new BigInteger(String.valueOf(Math.sqrt(numerator.doubleValue())));
BigInteger temp2=new BigInteger(String.valueOf(Math.sqrt(denominator.doubleValue())));
return new Rational(temp1,temp2);
}
package test;
import java.math.BigInteger;
/*---- -----Exercise14_19测试类------------*/
public class Exercise14_19 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//Rational r1 = new Rational(new BigInteger("4"),new BigInteger("2"));
//Rational r2 = new Rational(new BigInteger("2"),new BigInteger("3"));
Rational r1 = new Rational(new BigInteger("-60000000000000000000"),new BigInteger("200000000000000000"));
Rational r2 = new Rational(new BigInteger("20000000000000000000"),new BigInteger("300000000000000000"));
System.out.println(r1 + " + " + r2 + " = " + r1.add(r2));
System.out.println(r1 + " - " + r2 + " = "+ r1.subtract(r2));
System.out.println(r1 + " * " + r2 + " = "+ r1.multiply(r2));
System.out.println(r1 + " / " + r2 + " = "+ r1.divide(r2));
System.out.println(r2 + " is "+r2.doubleValue() );
Rational r3 = new Rational(new BigInteger("4"),new BigInteger("2"));
System.out.println(r3 + " sqr is "+r3.sqr().doubleValue());
}
}