class Complex{
double x,y;
Complex (doublex) {
this .x=x;
this .y=0;//为什么要赋值为0
}
complex (double x,double y){
this .x=x;
this .y=y;
}
public Complex add(Complex Z) {
double aa=x+Z.x;
double bb=y+Z.y;
returnnew Complex (aa,bb) ;
}
public Complex sub(Complex Z) {
double a a=x-Z.X;
double bb=y-Z.y;
returnnew Complex (aa,bb) ;
}
public Complex mult(Complex Z) {
double aa=x*Z.x-y*z.y;//这两步求差看不懂
double bb=y*2.×+×*2.y;//看不懂
returnnew Complex (aa,bb) ;
}
public String toString () {
//i不太清楚if语句的这部分
if(y==0){
return ""+x;
}
if(y>0){
return ""+x+”+"+y+"i";
}
return ""+x+"-“+(-y)+"i";
}
}
//上面的
class Test Complex{
public static voidmain( String[] args) {
Complex c1=new Complex (-2,3) ;
CompIex c2=new complex (4, -5) ;
Complex ac=c1.add(c2) ;
Complex sc=c1.sub(c2) ;
Complex mc=c1.mult(c2) ;
system .out.printIn(“两数之和:“+ac.tostring())i
System .out.println("两数之差:"+sc.toString()) ;
system .out.printin(“两数之积:“+mc.tostring() ;
}
}
java关于Complex类,程序有一部分不清楚什么意思,希望解释一下
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 萌新驾到 2021-11-25 15:39关注
public Complex mult(Complex Z) { double aa=x*Z.x-y*z.y;//这两步求差看不懂 double bb=y*Z.×+×*Z.y;//看不懂 returnnew Complex (aa,bb) ; }
这个看不懂的话我们可以修改一下:
public Complex mult(Complex Z) { double aa=this.x*Z.x-this.y*z.y;// 将this.补全 double bb=this.y*Z.×+this.×*Z.y;// 将this.补全 returnnew Complex (aa,bb) ; }
在对象方法里面直接x这种,其实是使用的自己的x,写全的话应该是this.x,这里只是简写了一下
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录
悬赏问题
- ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
- ¥20 软件测试决策法疑问求解答
- ¥15 win11 23H2删除推荐的项目,支持注册表等
- ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
- ¥15 qt6.6.3 基于百度云的语音识别 不会改
- ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
- ¥15 神经网络怎么把隐含层变量融合到损失函数中?
- ¥15 lingo18勾选global solver求解使用的算法
- ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
- ¥20 测距传感器数据手册i2c