Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


chaitanya
jav a
1 Answer(s)      5 years and a month ago
Posted in : Design concepts & design patterns



Advertisement
View Answers

November 2, 2009 at 10:35 AM


Hi Friend,

Try the following code:

public class ComplexNumber{
private int a;
private int b;
public ComplexNumber(){
}

public ComplexNumber(int a, int b){
this.a =a;
this.b=b;
}
public String getComplexValue(){
if(this.b < 0){
return a+""+b+"i";
}
else{
return a+"+"+b+"i";
}
}

public static String addition(ComplexNumber num1, ComplexNumber num2){
int a1= num1.a+num2.a;
int b1= num1.b+num2.b;
if(b1<0){
return a1+""+b1+"i";
} else {
return a1+"+"+b1+"i";
}
}

public static void main(String args[]){
ComplexNumber com1 = new ComplexNumber(-2,-3);
ComplexNumber com2 = new ComplexNumber(-4,-5);
System.out.println(com1.getComplexValue());
System.out.println(com2.getComplexValue());
System.out.println("Addition of Complex Numbers are :" +ComplexNumber.addition(com1,com2));

}
}
Thanks


Related Tutorials/Questions & Answers:
jav-util.zip
jav-util.zip  i need to load a zipfile in to my class while executing and i have extract each file in that zip and a particular file content i need to desplay how can i do this please help me
jav
Advertisements
JAv method overloading
JAv method overloading  What restrictions are placed on method overloading
jav compolation error - Java Beginners
jav compolation error  find symbol error
jav beginners - Java Beginners
jav beginners  pl. let me know the logic and the program to print the prime and twin prim numbers thanks  Hi Friend, Try the following code: class TwinPrimes{ public static void main (String
Jav Applets - Applet
Jav Applets  I need to write a small payroll program, using applet, that provides a text field for the number of hours, a text field for the pay rate, and a non-editable text field for the output. It should also also provide
jav a - Design concepts & design patterns
jav a  Q.1. Write a program in Java to perform the addition of two complex numbers.   Hi Friend, Try the following code: public class ComplexNumber{ private int a; private int b; public ComplexNumber
How to learn Java easily?
the basic, he/she can get an entry in the Jav world. From then on it depends
Control Tags-If / Else If / Else
:if>   <s:elseif test="%{#technologyName=='Jav'}">
Advertisements
 

 

 

DMCA.com