April 30, 2009 at 5:22 PM
Hi Friend,
Here is the full example code for your problem as given below. Please try the following code to solve your problem.
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 String substraction(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 String multiplication(ComplexNumber num1, ComplexNumber num2){
int a1= num1.a*num2.a;
int b1= num1.b*num2.b;
int vi1 = num1.a * num2.b;
int vi2 = num2.a * num1.b;
int vi;
vi=vi1+vi2;
if(vi<0){
return a1-b1+""+vi+"i";
} else {
return a1-b1+"+"+vi+"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 both Complex Numbers are :" +ComplexNumber.addition(com1,com2));
System.out.println("Substraction of both Complex Numbers are :" +ComplexNumber.substraction(com1,com2));
System.out.println("Multiplication of both Complex Numbers are :" +ComplexNumber.multiplication(com1,com2));
}
}
Thanks
RoseIndia Team
Related Tutorials/Questions & Answers:
java programmes - Java Beginnersjava programmes Can you please send me the
programmes for IT Deptartment.The subject code is IT2305.Based on new syllabus as per Anna University for 2008 regulation.It contains 12
programmes data science graduate programmesdata science graduate programmes Hi,
I am beginner in Data Science and machine learning field. I am searching for
the tutorials to learn:
data science graduate
programmes
Try to provide me good examples or tutorials links
Advertisements
char array javachar array java char array
programmes in java
All capital letters should be replaced with the next letter
where to start - Java Beginnerswhere to start Myself being a java beginner want to know wat is that I shall start practicing from the day one to make myself get the knowledge of java.Shall i get a series of questions or
programmes for a beginner to work
generics - Java Beginnersgenerics simple notes on Generics as well some
programmes, with its added advantages for java... Hi Friend,
If you want to take an element from the Collection, you have to cast the type of element that is stored
still error programmes with tools lik button,textfield etc.. and ds line "private void
Core Java Online Training and developing
programmes has become trendy jobs. To be a part of this contemporary... consist of a single page or a set of mini
programmes or sections. The support for such
programmes is provided through Struts, Server Pages (JSPs), Servlet
The Best We Offer_TO_REPLACE_2
We offer quality customised corporate training
programmes..., we do conduct short term development
programmes at our own business premises
java bean - EJB for the programmer where as in ejb these middle ware services are built in
programmes still error making
programmes with tools lik button,textfield etc.. and ds line "private void
iPhone Icon Design programmes
in itself and on the basis of icons we can recognize the applications
Kerala Beaches Tour is reserved for cultural
programmes like
Kathakali dance performance. Return
JSF Training of RoseIndia. If you try to apply the codes for developing the
programmes, we claim
PHP Training trained person for scripting the code for the simple
programmes. ADS_TO_REPLACE_2
Open Source ISO programmes and more often than not each one has its own format. In order