zoukankan      html  css  js  c++  java
  • 100到简单加减乘除算法的程序

    public class Complex {   
        double real; 
        double image;   
           
        Complex(){    
            Scanner input = new Scanner(System.in); 
            double real = input.nextDouble(); 
            double image = input.nextDouble(); 
            Complex(real,image); 
        
       
        private void Complex(double real, double image) {
            
            this.real = real; 
            this.image = image; 
        
       
        Complex(double real,double image){   
            this.real = real; 
            this.image = image; 
        
       
        public double getReal() { 
            return real; 
        
       
        public void setReal(double real) { 
            this.real = real; 
        
       
        public double getImage() { 
            return image; 
        
       
        public void setImage(double image) { 
            this.image = image; 
        
           
        Complex add(Complex a){
            double real2 = a.getReal(); 
            double image2 = a.getImage(); 
            double newReal = real + real2; 
            double newImage = image + image2; 
            Complex result = new Complex(newReal,newImage); 
            return result; 
        
           
        Complex sub(Complex a){
            double real2 = a.getReal(); 
            double image2 = a.getImage(); 
            double newReal = real - real2; 
            double newImage = image - image2; 
            Complex result = new Complex(newReal,newImage); 
            return result; 
        
           
        Complex mul(Complex a){   
            double real2 = a.getReal(); 
            double image2 = a.getImage(); 
            double newReal = real*real2 - image*image2; 
            double newImage = image*real2 + real*image2; 
            Complex result = new Complex(newReal,newImage); 
            return result; 
        
           
        Complex div(Complex a){   
            double real2 = a.getReal(); 
            double image2 = a.getImage(); 
            double newReal = (real*real2 + image*image2)/(real2*real2 + image2*image2); 
            double newImage = (image*real2 - real*image2)/(real2*real2 + image2*image2); 
            Complex result = new Complex(newReal,newImage); 
            return result; 
        
           
        public void print(){
            if(image > 0){ 
                System.out.println(real + " + " + image + "i"); 
            }else if(image < 0){ 
                System.out.println(real + "" + image + "i"); 
            }else
                System.out.println(real); 
            
        
    }
  • 相关阅读:
    java object bean 转map
    常用css
    mysql 生成max+1编号
    MySql避免重复插入记录方法(ignore,Replace,ON DUPLICATE KEY UPDATE)
    cookie记住账户密码
    session有效时间
    常用jstl
    高性能MySQL--innodb中事务的隔离级别与锁的关系
    mysql8.0.11的坑早知道
    git进阶--你可能不知道的很好用git功能
  • 原文地址:https://www.cnblogs.com/tanmengjia39/p/6550449.html
Copyright © 2011-2022 走看看