public class TextComplexNumber { public static void main(String[] args){ // TODO Auto-generated method stub//创建复数c1=2.0+4.0i ComplexNumber c1=new ComplexNumber(2,4); ComplexNumber c2=new ComplexNumber(2,4); System.out.println("c1+c2="+c1.add(c2)); System.out.println("c1/c2="+c1.divide(c2)); //equals方法:比较两个对象是否相等,结果为boolean System.out.println("c1.equals(c2)="+c1.equals(c2)); //hashCode方法:获得对象的hash码,结果为int类型 System.out.println("c1.hashCode="+c1.hashCode()); System.out.println("c2.hashCode="+c2.hashCode()); }}控制台显示的结果为:c1.equals(c2)=falsec1.hashCode=366712642c2.hashCode=1829164700
添加回答
举报
0/150
提交
取消