biile 2021-11-12 17:43 采纳率: 75%
浏览 35
已结题

java编译出现这个是什么意思呀=(

img

import java.util.Scanner;
public class ImpComplex{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double real1=in.nextDouble();
        double image1=in.nextDouble();
        double real2=in.nextDouble();
        double image2=in.nextDouble();
        ComplexNumber a=new ComplexNumber(real1,image1);
        ComplexNumber b=new ComplexNumber(real2,image2);
        System.out.printf("Real:%.2f imaginary:%.2f ",a.getRealPart(),a.getImaginaryPart());
        System.out.printf("Real:%.2f imaginary:%.2f ",b.getRealPart(),b.getImaginaryPart());
        System.out.println(a.complexAdd(b));
        System.out.println(a.complexMinus(b));
        System.out.println(a.complexMulti(b));
        System.out.println(a.complexDivide(b));
    }
}

class ComplexNumber {
    private double m_dRealPart;
    private double m_dImaginPart;
 
    ComplexNumber(double r, double i) {
        this.m_dRealPart = r;
        this.m_dImaginPart = i;
    }
 
    ComplexNumber() {
        this.m_dRealPart = 0;
        this.m_dImaginPart = 0;
    }
 
    public double getImaginaryPart() {
        return this.m_dImaginPart;
    }
    public double getRealPart() {
        return this.m_dRealPart;
    }
    public ComplexNumber setRealPart(double d){
        this.m_dRealPart = d;
        return this;
    }
    public ComplexNumber setImaginaryPart(double d){
        this.m_dImaginPart = d;
        return this;
    }
    public ComplexNumber complexConjugate(){
        ComplexNumber c = new ComplexNumber();
        c.m_dRealPart = this.m_dRealPart;
        c.m_dImaginPart = -this.m_dImaginPart;
        return c;
    }
    public ComplexNumber complexAdd(ComplexNumber c) {
        ComplexNumber a = new ComplexNumber();
        a.m_dRealPart = this.m_dRealPart + c.m_dRealPart;
        a.m_dImaginPart = this.m_dImaginPart + c.m_dImaginPart;
        return a;
    }
 
    public ComplexNumber complexAdd(double c){
        ComplexNumber a = new ComplexNumber();
        a.m_dRealPart = this.m_dRealPart + c;
        a.m_dImaginPart = this.m_dImaginPart;
        return a;
    }
    public ComplexNumber complexMinus(ComplexNumber c) {
        ComplexNumber a = new ComplexNumber();
        a.m_dRealPart = this.m_dRealPart - c.m_dRealPart;
        a.m_dImaginPart = this.m_dImaginPart - c.m_dImaginPart;
        return a;
    }
    public ComplexNumber complexMinus(double c) {
        ComplexNumber a = new ComplexNumber();
        a.m_dRealPart = this.m_dRealPart - c;
        a.m_dImaginPart = this.m_dImaginPart;
        return a;
    }
 
    public ComplexNumber complexMulti(ComplexNumber c) {
        ComplexNumber a = new ComplexNumber();
        a.m_dRealPart = this.m_dRealPart * c.m_dRealPart - this.m_dImaginPart * c.m_dImaginPart;
        a.m_dImaginPart = this.m_dRealPart * c.m_dImaginPart + this.m_dImaginPart * c.m_dRealPart;
        return a;
    }
 
    public ComplexNumber complexMulti(double c) {
        ComplexNumber a = new ComplexNumber();
        a.m_dRealPart = this.m_dRealPart * c;
        a.m_dImaginPart = this.m_dImaginPart * c;
        return a;
    }

    public ComplexNumber complexDivide(ComplexNumber c) {
        ComplexNumber a = new ComplexNumber();
        a.m_dRealPart = (c.m_dRealPart * this.m_dRealPart + c.m_dImaginPart * this.m_dImaginPart) / (c.m_dRealPart * c.m_dRealPart + c.m_dImaginPart * c.m_dImaginPart);
        a.m_dImaginPart = (c.m_dRealPart * this.m_dImaginPart - this.m_dRealPart * c.m_dImaginPart) / (c.m_dRealPart * c.m_dRealPart + c.m_dImaginPart * c.m_dImaginPart);
        return a;
    }
 
    public ComplexNumber complexDivide(double c){
        ComplexNumber a = new ComplexNumber();
        a.m_dRealPart = this.m_dRealPart / c;
        a.m_dImaginPart = this.m_dImaginPart /c;
        return a;
    }
    public String toString(){
        return(this.m_dRealPart + "+" + this.m_dImaginPart + "i");
    }
}

  • 写回答

3条回答 默认 最新

  • I'Msohs 2021-11-12 17:51
    关注

    代码写的有问题,用idea或者myeclipse吧,

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 11月12日
  • 修改了问题 11月12日
  • 创建了问题 11月12日

悬赏问题

  • ¥15 在虚拟机中安装flash code
  • ¥15 单片机stm32f10x编写光敏电阻调节3.3伏大功率灯亮度(光强越大灯越暗,白天正常光强灯不亮,使用ADC,PWM等模块)望各位找一下错误或者提供一个可实现功能的代码
  • ¥20 verilog状态机方法流水灯
  • ¥15 pandas代码实现不了意图
  • ¥15 GD32H7 从存储器到外设SPI传输数据无法重复启用DMA
  • ¥25 LT码在高斯信道下的误码率仿真
  • ¥45 渲染完成之后将物体的材质贴图改变,自动化进行这个操作
  • ¥15 yolov5目标检测并显示目标出现的时间或视频帧
  • ¥15 电视版的优酷可以设置电影连续播放吗?
  • ¥50 复现论文;matlab代码编写