| 50 | } |
| 51 | // Function to divide two complex numbers |
| 52 | public void div() { |
| 53 | double d1, d2, d3, d4, d5, d6; |
| 54 | if (real2 == 0 && imag2 == 0) { |
| 55 | System.out.println("Division cannot be performed."); |
| 56 | } |
| 57 | else { |
| 58 | d1 = real1 * real2; // For numerator |
| 59 | d2 = (real1 * imag2) + (real2 * imag1); // For numerator |
| 60 | d4 = (real2 * real2); // For denominator |
| 61 | d5 = (real2 * (-1) * imag2) + (real2 * (-1) * imag2); // For denominator |
| 62 | d6 = d4 + d5; // For denominator |
| 63 | if (imag1 == 0 || imag2 == 0) { |
| 64 | d3 = 0; |
| 65 | } |
| 66 | else { |
| 67 | d3 = (-1) * (imag1 * imag2); |
| 68 | } |
| 69 | d1 = d1 + d3; |
| 70 | System.out.println("Division is: " + d1/d6 + " + " + d2/d6 + "i"); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | }; |
| 75 | |