Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Complex{
- public double real,imaginar;
- public static int nrShow=0;
- public Complex(double r ,double i ){
- this.real=r;
- this.imaginar=i;
- }
- public double modulComplex(){
- return Math.sqrt(this.real*this.real + this.imaginar*this.imaginar);
- }
- public void showComplex(){
- System.out.println(this.real+"+i*"+this.imaginar);
- this.nrShow++;
- }
- public Complex getSum(Complex numar){
- double si=this.real+numar.real;
- double ri=this.imaginar+numar.imaginar;
- Complex resultSum=new Complex(si,ri);
- return resultSum;
- }
- public static int getShow(){
- return nrShow;
- }
- }
- class ClientComplex{
- public static void main(String[] args){
- Complex primNr=new Complex(3,4);
- System.out.print("Modul Numar Complex : ");
- System.out.println(primNr.modulComplex());
- primNr.showComplex();
- System.out.print("Suma complex: ");
- Complex twoNr = new Complex(3,6);
- primNr.getSum(twoNr).showComplex();
- System.out.println("Afisari:"+ Complex.nrShow);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment