国产精品一区二区在线观看完整版,在线观看91精品国产性色,欧美日韩另类视频

杭州校區(qū)切換校區(qū)
圖標(biāo)

學(xué)習(xí)文章

當(dāng)前位置:首頁(yè) > >學(xué)習(xí)文章 > >

{Java培訓(xùn)}復(fù)數(shù)運(yùn)算

發(fā)布時(shí)間: 2017-06-16 10:51:04

要求是實(shí)現(xiàn)一個(gè)復(fù)數(shù)類(lèi),這個(gè)類(lèi)本身提供四則運(yùn)算,提示一下,該類(lèi)結(jié)構(gòu)是:

class Complex {

定義實(shí)部、虛部;

構(gòu)造方法定義;

四則運(yùn)算方法定義,如加法可定義為:

public Complex add(Complex oper){....}

其它的成員

}

使用該類(lèi)時(shí),可以

Complex a = new Complex(3.0, 4.), b = new Complex(3.5, 4.5), c;

c = a.add(b);

System.out.println("c="+c);

public class Complex

{

private double realPart;

private double imaginaryPart;

public Complex(double a, double b)

{

this.realPart = a;

this.imaginaryPart = b;

}

public Complex add(Complex a)

{

Complex result = new Complex(this.realPart + a.realPart, this.imaginaryPart + a.imaginaryPart);//(why?)

return result;

}

public Complex decrease(Complex a)

{

Complex result = new Complex(this.realPart - a.realPart, this.imaginaryPart - a.imaginaryPart);//(why?)

return result;

}

public Complex multiply(Complex a)

{

double newReal = this.realPart*a.realPart - this.imaginaryPart * a.imaginaryPart;

double newImaginary = this.realPart*a.imaginaryPart + this.imaginaryPart * a.realPart;

Complex result = new Complex(newReal, newImaginary);

return result;

}

public Complex divide(Complex a)

{

Complex conjugate = new Complex(this.realPart, -this.imaginaryPart);

Complex multiplication = conjugate.multiply(a);

multiplication.realPart /= this.realPart*this.realPart + this.imaginaryPart * this.imaginaryPart;

multiplication.imaginaryPart /= this.realPart*this.realPart + this.imaginaryPart * this.imaginaryPart;

return multiplication;

}

public String toString()

{

String show = this.realPart + " + " + this.imaginaryPart + "i";

return show;

}

public static void main(String [] args)

{

Complex a = new Complex (2, 3);

Complex b = new Complex (1,1);

System.out.println((a.add(b)).toString());

System.out.println((a.decrease(b)).toString());

System.out.println((a.multiply(b)).toString());

System.out.println((a.divide(b)).toString());

 

 

 

 

}

}

上一篇: {華為HCNP-RS}路由器協(xié)議及內(nèi)含屬性介紹

下一篇: {Java培訓(xùn)}泛型的一個(gè)簡(jiǎn)單例子

在線(xiàn)咨詢(xún) ×

您好,請(qǐng)問(wèn)有什么可以幫您?我們將竭誠(chéng)提供最優(yōu)質(zhì)服務(wù)!

<bdo id="pdyax"></bdo>

    <pre id="pdyax"></pre>
    <menuitem id="pdyax"></menuitem>
      <form id="pdyax"><tbody id="pdyax"></tbody></form>

      1. <center id="pdyax"><center id="pdyax"></center></center>
          1. 主站蜘蛛池模板: 当雄县| 红原县| 龙江县| 崇阳县| 扎鲁特旗| 溆浦县| 澄城县| 富顺县| 嘉峪关市| 石渠县| 醴陵市| 盘山县| 镇沅| 博兴县| 尉犁县| 松原市| 光泽县| 青州市| 文登市| 皋兰县| 玛沁县| 横山县| 吴旗县| 东乌珠穆沁旗| 嵊泗县| 武安市| 通江县| 上杭县| 乌鲁木齐县| 楚雄市| 肥城市| 和政县| 奉新县| 太白县| 靖安县| 周宁县| 安福县| 江阴市| 丰镇市| 南郑县| 清涧县|
            icon
            在线咨询