Graderpractice for programmers

Back to 254275 OOP Lab 5-10

Q9. Complex number

Problem

Complex numbers are those that have an imaginary part and a real part associated with it. They can be added and subtracted like regular numbers. The real parts and imaginary parts are respectively added or subtracted or even multiplied and divided.
The value of a complex numbers is calculated by The real parts + reals parts and imaginary part+ parts Complete the class Complex by adding a constructor and methods for getting real,img and sum

 public static void main(String args[])
 {
     Scanner sc = new Scanner(System.in);
     ComplexNumber c1 = new ComplexNumber(sc.nextDouble(),sc.nextDouble());
     ComplexNumber c2 = new ComplexNumber(sc.nextDouble(),sc.nextDouble());
     ComplexNumber ss = sum(c1, c2);
     System.out.printf("The sum of two complex numbers is "+String.format("%.1f",ss.real)+" + "+String.format("%.1f",ss.img) +"i");
 }

Examples

Input

12
3.3
13.4
5.3

Output

The sum of two complex numbers is 25.4 + 8.6i

Submit your solution

java