jav a

jav a

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
ModuleNotFoundError: No module named 'jav'
ModuleNotFoundError: No module named 'jav'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'jav' How to remove the ModuleNotFoundError: No module named 'jav' error
ModuleNotFoundError: No module named 'jav'
ModuleNotFoundError: No module named 'jav'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'jav' How to remove the ModuleNotFoundError: No module named 'jav' error
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
jav - Spring
Control Tags-If / Else If / Else
:elseif test="%{#technologyName=='Jav'}">   <div><s
How to learn Java easily?
_TO_REPLACE_2 Once the beginner has learnt the basic, he/she can get an entry in the Jav

Ads