0% found this document useful (0 votes)
4 views1 page

Java Program for Complex Number Sum

The document contains a Java program that defines a Complex class for representing complex numbers with real and imaginary parts. It includes a method to sum two complex numbers and a main class that takes user input for two complex numbers, computes their sum, and displays the result. The program utilizes the Scanner class for input and demonstrates basic object-oriented programming concepts in Java.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Java Program for Complex Number Sum

The document contains a Java program that defines a Complex class for representing complex numbers with real and imaginary parts. It includes a method to sum two complex numbers and a main class that takes user input for two complex numbers, computes their sum, and displays the result. The program utilizes the Scanner class for input and demonstrates basic object-oriented programming concepts in Java.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import [Link].

*;
class Complex
{
double real,img;
Complex(double r, double i)
{
[Link] = r;
[Link] = i;
}
static Complex sum(Complex c1, Complex c2)
{
Complex temp = new Complex(0,0);
[Link] = [Link] + [Link];
[Link] = [Link] + [Link];
return temp;
}
}

class ComplexArithmetic
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
double rp,ip;
[Link]("Enter real and imaginary parts of first Complex
number:");
rp=[Link]();
ip=[Link]();
Complex c1 = new Complex(rp,ip);
[Link]("Enter real and imaginary parts of second Complex
number:");
rp=[Link]();
ip=[Link]();
Complex c2 = new Complex(rp,ip);
Complex temp = [Link](c1, c2);
[Link]("Sum of Numbers is: "+ [Link]+" + "+ [Link]
+"i");
}
}

You might also like