java other_帮我看下里面other是什么意思?

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

public class ComplexTest {

public static void main(String[] args) {

Complex c = new Complex(3,5);

Complex d = new Complex(2,2);

System.out .println("复数运算");

System.out .println("第一个复数>>" + c);

System.out .println("第二个复数>>" + d);

System.out .println("两复数相加");

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

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

System.out .println("两复数相减");

System.out .println(c + " - " + d + " = " + c.subtract(d));

System.out .println(c + " - " + 2 + ")" + " = " + c.subtract(2));

System.out .println("两复数相乘");

System.out .println(c + " * " + d + " = " + c.multiply(d));

System.out .println(c + " * " + 2 + ")" + " = " + c.multiply(2));

}

}

//声明复数类

class Complex{

private double real;

private double imaginary;

//构造方法

public Complex(){

this(0.0,0.0);

}

public Complex(double real, double imaginary){

this.real=real;

this.imaginary=imaginary;

}

public Complex(Complex c){

this(c.getReal(), c.getImaginary());

}

//get,set方法

public double getReal() {

return real;

}

public void setReal(double real) {

this.real = real;

}

public double getImaginary() {

return imaginary;

}

public void setImaginary(double imaginary) {

this.imaginary = imaginary;

}

//两个复数相加

public Complex add(double real){

return new Complex(this.real+real,this.imaginary);

}

public Complex add(Complex other){

return add(this,other);

}

private Complex add(Complex c1,Complex c2){

return new Complex(c1.real+c2.real,c1.imaginary+c2.imaginary);

}

//两个复数相减

public Complex subtract(double real){

return new Complex(this.real - real,this.imaginary);

}

public Complex subtract(Complex other){

return subtract(this, other);

}

private Complex subtract(Complex c1,Complex c2){

return new Complex(c1.real - c2.real,c1.imaginary - c2.imaginary);

}

//两个复数相乘

public Complex multiply(double c){

return new Complex(this.real * c,this.imaginary * c);

}

public Complex multiply(Complex other){

return multiply(this, other);

}

private Complex multiply(Complex c1, Complex c2){

return new Complex(c1.real* c2.real - c1.imaginary* c2.imaginary,

c1.real* c2.imaginary + c2.real* c1.imaginary);

}

public String toString(){

return"("+real+"+"+imaginary+"i"+")";

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值