12/19lab 1
class Number{
public double real;
public double complex;
public Number(double real,double complex )
{this.real=real;
this.complex=complex;
}
public void Add(Number q3)
{
this.real=this.real+q3.real;
this.complex=this.complex+q3.complex;
}
}
class Compare {
public static void main(String[] args)
{
Number num1=new Number(2,3);
Number num2=new Number(4,5);
System.out.println("Number1 real:"+num1.real);
System.out.println("Number1 complex:"+num1.complex+"i");
System.out.println("Number2 real:"+num2.real);
System.out.println("Number2 complex:"+num2.complex+"i");
num1.Add(num2);
System.out.println("Number complex:"+num1.real);
System.out.println("Number complex:"+num1.complex+"i");
}
}
0 Comments:
Post a Comment
<< Home