You are on page 1of 3

COMPLEX NUMBER MANIPULATION

public class ComplexNumber


{private int a;private int b;public ComplexNumber()
{12
}public ComplexNumber(int a, int b){
this.a =a;this.b=b;}
public Strin etComplex!alue(){i"(this.b # $){return
a%&&%b%&i&;}else{return a%&%&%b%&i&;}}public static Strin
a''ition(ComplexNumber num1, ComplexNumber num2){int
a1= num1.a%num2.a;int b1= num1.b%num2.b;i"(b1#$){return
a1%&&%b1%&i&;} else {return a1%&%&%b1%&i&;}}public static
Strin substraction(ComplexNumber num1, ComplexNumber
num2){int a1= num1.a(num2.a;int b1= num1.b(
num2.b;i"(b1#$){1)
return a1%&&%b1%&i&;} else {return
a1%&%&%b1%&i&;}}public static Strin
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;i"(vi#$){return a1(b1%&&%vi%&i&;} else {return
a1(b1%&%&%vi%&i&;}}public static voi' main(Strin ars+,)
{ComplexNumber com1 = ne- ComplexNumber((2,(
));ComplexNumber com2 = ne- ComplexNumber((.,(
/);S0stem.out.println(com1.etComplex!alue());S0stem.o
ut.println(com2.etComplex!alue());S0stem.out.println(&
1''ition o" both Complex Numbers
are 2&%ComplexNumber.a''ition(com1,com2));S0stem.out.pri
ntln(&Substraction o" both Complex Numbers
are 2&%ComplexNumber.substraction(com1,com2));1.
S0stem.out.println(&3ultiplication o" both Complex
Numbers
are 2&%ComplexNumber.multiplication(com1,com2));}}
OUTPUT:
4256avaexecute78avac
ComplexNumber.8ava4256avaexecute78ava ComplexNumber(2(
)i(.(/i1''ition o" both Complex Numbers are 2(9(
:iSubstraction o" both Complex Numbers are 2
2%2i3ultiplication o" both Complex Numbers are 2(;%22i1/
<esult2=hus the complex number proram -as
execute' an' compile' success"ul0.
4x.No2)
DATE CLASS SIMILAR TO JAVA.UTIL
PACKAGEAIM:
=o -rite a 8ava proram to 'ispla0 the 'ates o" be"ore an'
a"ter 'a0s "or aiven 'ate.
ALGORITHM:
1. St ar t t he pr or am. 2.Create a class -ith name
>ate).>eclare the variables month, 'a0, 0ear as private
an' create constructor -itharuments.19
..Chec? the con'ition "or exception. @" the 'ate is
vali', @t -ill procee' theproram other-ise 'ispla0 the
exception A@nvali'B./.Cse Doolean t0pe "or metho' to
return the values as either true or "alse.9.Chec? the
values "or month an' values "or 'a0 usin i"
loops.;.Chec? the 0ear usin i" loop -hether it is
leap 0ear or not.:.>e"ine metho's is1"ter() an'
isDe"ore() in proram.E.>e"ine metho' compare=o()
to compare the 'ate.1$.@n main() create ob8ect to'a0 an'
ive current 'ate as value "or constructor"iel's11.Call the
all metho's to 'ispla0 the 'ates.
DATE CLASS SIMILAR TO JAVA.UTIL PACKAGE
public class >ate {private "inal int month;private "inal int
'a0;1;

You might also like