>
亚州城ca88手机版「欢迎您」
做最好的网站

有理数类,少儿看图轻松记单词

- 编辑:亚州城ca88手机版 -

有理数类,少儿看图轻松记单词

图片 1孩童看图轻松记单词:divide分开

英特网随意一搜,是这么写的:

import java.math.BigInteger;

divide:

ROUND_CEILING

public class Rational extends Number implements Comparable {

divide[英][dɪ'vaɪd]

Rounding mode to round towards positive infinity.

private BigInteger numerator;// 分子
private BigInteger denominator;// 分母

[美][dɪˈvaɪd]

向正无穷方向舍入

/**
* @param args
*/
public static void main(String[] args) {

vt.& vi。分; 划分; 分离; (使)产素不相识歧;

ROUND_DOWN

// TODO Auto-generated method stub
Rational rational1 = new Rational(new BigInteger(1 ""),
new BigInteger(10 ""));
Rational rational2 = new Rational(new BigInteger(1 ""),
new BigInteger(-10 ""));
System.out.println(rational1.add(rational2));
System.out.println(rational1.subtract(rational2));
System.out.println(rational1.multiple(rational2));
System.out.println(rational1.divide(rational2));
}

n。分水岭,分界线; 分配;

Rounding mode to round towards zero.

public Rational() {

第多人称单数:divides过去分词:divided未来实行时:dividing过去式:divided

向零方向舍入

// TODO Auto-generated constructor stub
this(BigInteger.ZERO, BigInteger.ONE);
}

The dispute deepens their divide。

ROUND_FLOOR

public Rational(BigInteger numerator, BigInteger denominator) {

此番纷争将强化他们的区别。

Rounding mode to round towards negative infinity.

BigInteger gcd = gcd(numerator, denominator);
this.numerator = ((denominator.compareTo(BigInteger.ZERO)) > 0 ? BigInteger.ONE
: new BigInteger(-1 "")).multiply(numerator).divide(gcd);
this.denominator = denominator.abs().divide(gcd);
}

(沪江朝鲜语)

向负无穷方向舍入

public static BigInteger gcd(BigInteger a, BigInteger b) {

ROUND_HALF_DOWN

BigInteger n1 = a.abs();
BigInteger n2 = b.abs();
BigInteger remainder = n1.remainder(n2);
while (remainder.compareTo(BigInteger.ZERO) > 0) {
n1 = n2;
n2 = remainder;
remainder = n1.remainder(n2);
}
return n2;
}

Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.

public BigInteger getNumerator() {

向(距离)如今的一方面舍入,除非两侧(的偏离)是相等,假诺是如此,向下舍入, 举个例子1.55 保留一人小数结果为1.5

return numerator;
}

ROUND_HALF_EVEN

public BigInteger getDenominator() {

Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.

return denominator;
}

向(距离)这两天的单方面舍入,除非两侧(的偏离)是相等,借使是这么,假若保留位数是奇数,使用ROUND_HALF_UP ,假使是偶数,使用ROUND_HALF_DOWN

public Rational add(Rational secondRational) {

ROUND_HALF_UP

BigInteger n = numerator.multiply(secondRational.getDenominator()).add(
denominator.multiply(secondRational.getNumerator()));
BigInteger d = denominator.multiply(secondRational.getDenominator());
return new Rational(n, d);
}

Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.

public Rational subtract(Rational secondRational) {

向(距离)近来的一方面舍入,除非两侧(的距离)是特别,借使是如此,向上舍入, 1.55保留一人小数结果为1.6

BigInteger n = numerator.multiply(secondRational.getDenominator())
.subtract(denominator.multiply(secondRational.getNumerator()));
BigInteger d = denominator.multiply(secondRational.getDenominator());
return new Rational(n, d);
}

ROUND_UNNECESSARY

public Rational multiple(Rational secondRational) {

Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary.

BigInteger n = numerator.multiply(secondRational.getNumerator());
BigInteger d = denominator.multiply(secondRational.getDenominator());
return new Rational(n, d);
}

计量结果是纯粹的,没有须求舍入情势

public Rational divide(Rational secondRational) {

ROUND_UP

BigInteger n = numerator.multiply(secondRational.getDenominator());
BigInteger d = denominator.multiply(secondRational.getNumerator());
return new Rational(n, d);
}

Rounding mode to round away from zero.

@Override
public boolean equals(Object obj) {

向远远地离开0的侧向舍入

// TODO Auto-generated method stub
if (this.getNumerator().compareTo(((Rational) obj).getNumerator()) == 0) {
return true;
}
else {
return false;
}
}

MathContext mathContext = new MathContext(2,RoundingMode.UP);

@Override
public String toString() {

BigDecimal test1 = BigDecimal.valueOf(19785.076);

// TODO Auto-generated method stub
if (denominator.compareTo(BigInteger.ONE) == 0) {
return numerator.toString();
}
else {
return numerator.toString() "/" denominator.toString();
}
}

本文由ca88手机版登录网页发布,转载请注明来源:有理数类,少儿看图轻松记单词