词条 | fraction |
释义 | 英语名词与c 英语中英语名词: fraction英音:['frækʃən]美音:['frækʃən] 词典解释 名词n. [C] 1.小部分;片段;碎片 He has done only a fraction of hishomework. 他只做了家庭作业的一小部分。2.些微,一点儿[S][(+of)] The story does not contain a fraction oftruth. 这故事没有一点真实性。3.【数】分数4.【化】馏分;级分 网络释义 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; } } |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。