Complex类实现Comparable<T>接口,提供按模比较复数大小的方法。
咋写不会求解!感谢大家
public class Complex implements Comparable<Complex>{
private float real;
private float image;
public void setReal(float real) {
this.real = real;
}
public void setImage(float image) {
this.image = image;
}
public float getReal() {
return real;
}
public float getImage() {
return image;
}
@Override
public int compareTo(Complex o) {
double a = Math.sqrt(real * real + image * image);
double b = Math.sqrt(o.getReal() * o.getReal() + o.getImage() * o.getImage());
return Double.compare(a, b);
}
}
如有帮助,请采纳支持一下。点击我回答右上角的【采纳】按钮。
您的问题已经有小伙伴解答了,请点击【采纳】按钮,采纳帮您提供解决思路的答案,给回答的人一些鼓励哦~~
ps:开通问答VIP,享受5次/月 有问必答服务,了解详情↓↓↓
【电脑端】戳>>> https://vip.csdn.net/askvip?utm_source=1146287632
【APP 】 戳>>> https://mall.csdn.net/item/52471?utm_source=1146287632