BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / java / #13003同步于 2010/1/18
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖

【求助】请牛人帮忙做道题,有BG哦~

ILoveColaCao
2010/1/18镜像同步11 回复
是弟弟让我帮忙做的,我也不会啊[em9] 哪位牛人帮帮忙做一下,不胜感激! 最好在明天中午之前,有BG哦~~~
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
greedisgood机器人#1 · 2010/1/19
【 在 ILoveColaCao 的大作中提到: 】 : : 是弟弟让我帮忙做的,我也不会啊[em9] : 哪位牛人帮帮忙做一下,不胜感激! : ................... public class Complex { private double re; private double im; public Complex() { } public Complex(double re) { this.re = re; } public Complex(double re, double im) { this.re = re; this.im = im; } private Complex inv() { if (abs() == 0) { return new Complex(); } else { return new Complex(re / ((re * re) + (im * im)), -(im / ((re * re) + (im * im)))); } } public double real() { return re; } public double imag() { return im; } public double abs() { return Math.sqrt((re * re) + (im * im)); } public Complex add(Complex c2) { return new Complex(this.re + c2.real(), this.im + c2.imag()); } public Complex sub(Complex c2) { return new Complex(this.re - c2.real(), this.im - c2.imag()); } public Complex mul(Complex c2) { return new Complex(this.re * c2.real() - this.im * c2.imag(), this.re * c2.imag() + this.im * c2.real()); } public Complex div(Complex c2) { return mul(c2.inv()); } @Override protected Complex clone() throws CloneNotSupportedException { return new Complex(re, im); } @Override public boolean equals(Object obj) { if (obj instanceof Complex) { return ((Complex) obj).real() == this.re && ((Complex) obj).imag() == this.im; } else { return false; } } @Override public int hashCode() { int hash = 5; hash = 61 * hash + (int) (Double.doubleToLongBits(this.re) ^ (Double.doubleToLongBits(this.re) >>> 32)); hash = 61 * hash + (int) (Double.doubleToLongBits(this.im) ^ (Double.doubleToLongBits(this.im) >>> 32)); return hash; } @Override public String toString() { if (this.im < 0) { return this.re + "" + this.im + "i"; } else if (this.im == 0) { return this.re + ""; } else { return this.re + "+" + this.im + "i"; } } public static void main(String args[]) throws CloneNotSupportedException { Complex c1 = new Complex(1, 2); Complex c2 = null; System.out.println(c2 = c1.clone()); System.out.println(c1.equals(c2)); System.out.println(c1.sub(c2)); System.out.println(c1.add(c2)); System.out.println(c1.mul(c2)); System.out.println(c1.div(c2)); System.out.println(c1.toString()); } }
greedisgood机器人#2 · 2010/1/19
lz把代码保存为Complex.java发给你弟弟就行了,他懂的。。
ericyosho机器人#3 · 2010/1/19
这是greedisgood第二次在没有提问人任何思考的情况下散发源代码了 (@@)~~ 我闭嘴了。
greedisgood机器人#4 · 2010/1/19
【 在 ericyosho 的大作中提到: 】 : 这是greedisgood第二次在没有提问人任何思考的情况下散发源代码了 : (@@)~~ : 我闭嘴了。 有什么说法吗?不让回复作业吗。置顶版规里没写啊。
heartofsea机器人#5 · 2010/1/19
外国学校?中国学校?
ILoveColaCao机器人#6 · 2010/1/19
德国的~ 已经收到很满意的答案了,谢谢大家的关注~~
fireflyk机器人#7 · 2010/1/20
【 在 greedisgood 的大作中提到: 】 : 有什么说法吗?不让回复作业吗。置顶版规里没写啊。 求教一个问题 hashCode里边的写法,乘以61啊,右移啊什么的 这些是一个既定的规则这么生成,还是你自己想的、自己规定的呢
Adun机器人#8 · 2010/1/21
5*61是啥概念?同不懂...
fireflyk机器人#9 · 2010/1/22
【 在 Adun 的大作中提到: 】 : 5*61是啥概念?同不懂... 《Effective Java》中也有乘以13再加7的一个生成hashCode的算法,不知道是什么习惯?