fraction(英语单词)

2023-02-07 62阅读

温馨提示:这篇文章已超过541天没有更新,请注意相关的内容是否还可用!

fraction

英语单词

英语名词:fraction英音:['frækʃən]美音:['frækʃən]词典解释名词

n.分式;小部分;少许;分数;片段;vt.分开;把…分成几部分。

中文名小部分
外文名fraction
读音['frækʃən]
性质英语名词

网络释义

1.分数;分式

数学英语词汇 (F-H)-英语词汇汇总-词...

fraction 分数;分式

.2.份数;馏分

纸业专业英语词汇翻译(F3)-英语阅读网 ...

fraction 份数;馏分

.3.部分,成分

医学翻译词汇F - 『原版英语』 阅读网

fraction 部分,成分

c语言中

例:创建一个Fraction类执行分数运算。要求如下:(1)用整形数表示类的private成员变量:f1和f2.(2)提供构造方法,将分子存入f1和f2,分母存入f2.。1)用整形数表示类的private成员变量:f1和f2.(2)提供构造方法,将分子存入f1和f2,分母存入f2.。

public class Fraction {

public static void main(String args) {

//测试代码

Fraction f1 = new Fraction(1, 2);

Fraction f2 = new Fraction(1, 3);

System.out.println("分数f1 ==" + f1);

System.out.println("分数f2 ==" + f2);

System.out.println("分数f1 浮点数 ==" + f1.doubleValue());

System.out.println("分数f2浮点数 ==" + f2.doubleValue());

System.out.println("分数f1+f2 ==" + f1.add(f2));

System.out.println("分数f1-f2 ==" + f1.sub(f2));

System.out.println("分数f1*f2 ==" + f1.multiply(f2));

System.out.println("分数f1/f2 ==" + f1.div(f2));

}

private int f1; //分子

private int f2; //分母

public Fraction(int f1, int f2) {

if(f2 == 0){ throw new IllegalArgumentException("分母不能为0");}

this.f1 = f1;

this.f2 = f2;

}

/***/

public Fraction add(Fraction other){

int fm = this.f2 * other.f2;

int fz = this.f1 * other.f2 + other.f1 * this.f2;

return new Fraction(fz, fm);

}

/***/

public Fraction sub(Fraction other){

int fm = this.f2 * other.f2;

int fz = this.f1 * other.f2 - other.f1 * this.f2;

return new Fraction(fz, fm);

}

/***/

public Fraction multiply(Fraction other){

int fm = this.f2 * other.f2;

int fz = this.f1 * other.f1;

return new Fraction(fz, fm);

}

/***/

public Fraction div(Fraction other){

if(other.doubleValue() == 0.0 ){

throw new IllegalArgumentException("0不能做为除数");

}

int fm = this.f2 * other.f1;

int fz = this.f1 * other.f2;

return new Fraction(fz, fm);

}

public String toString(){

return f1 + "/" + f2;

}

public double doubleValue(){

return 1.0 * f1 / f2;

}

}

参考资料

1.fraction·海词

目录[+]