Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java complex numbers

Complex numbers are those that have an imaginary part and a real part associated 
with it. They can be added and subtracted like regular numbers. The real parts 
and imaginary parts are respectively added or subtracted or even multiplied and divided.


public class Demo{
   double my_real;
   double my_imag;
   public Demo(double my_real, double my_imag){
      this.my_real = my_real;
      this.my_imag = my_imag;
   }
   public static void main(String[] args){
      Demo n1 = new Demo(76.8, 24.0),
      n2 = new Demo(65.9, 11.23),
      temp;
      temp = add(n1, n2);
      System.out.printf("The sum of two complex numbers is %.1f + %.1fi", temp.my_real,
      temp.my_imag);
   }
   public static Demo add(Demo n1, Demo n2){
      Demo temp = new Demo(0.0, 0.0);
      temp.my_real = n1.my_real + n2.my_real;
      temp.my_imag = n1.my_imag + n2.my_imag;
      return(temp);
   }
}
Comment

complex numbers in java

class ComplexNumber {
 
    int real, image;
 
 
    public ComplexNumber(int r, int i)
    {
        this.real = r;
        this.image = i;
    }
 
  
    public void showC()
    {
        System.out.print(this.real + " +i" + this.image);
    }
 
    
    public static ComplexNumber add(ComplexNumber n1,
                                    ComplexNumber n2)
    {
 
        
        ComplexNumber res = new ComplexNumber(0, 0);
 
     
        res.real = n1.real + n2.real;
 
       
        res.image = n1.image + n2.image;
 
     
        return res;
    }
Comment

PREVIOUS NEXT
Code Example
Java :: MD5 java 
Java :: how to convert double to int in java 
Java :: mongorepository spring boot custom query 
Java :: double to int 
Java :: Java @Deprecated annotation 
Java :: control structures in java 
Java :: get value from Spring application.properties 
Java :: java to c# converter 
Java :: creating an object in java 
Java :: what is construct in java 
Java :: super class tostring java 
Java :: islowercase java 
Java :: firestore java timestamp 
Java :: hashmap java 
Java :: How to perform in-order traversal of a binary tree? 
Java :: math.pow(x2-x1,2) 
Java :: java long literal 
Java :: arraylist methods in java 
Java :: check if object is empty java 8 
Java :: Java float Keyword 
Java :: Is the main method compulsory in Java? 
Java :: log.d() andriod 
Java :: java regex of eauations 
Java :: actionlistener 
Java :: Java try Keyword 
Java :: how to pass parameters to xsl file 
Java :: Exercise. Create a simple Java program using array named SumOfArray.java that will accept an input of whole numbers or floating point numbers and will return the Sum result. The program must accept at least 5 numbers. 
Java :: grava 
Java :: springBoot Register a Custom Auto-Configuration 
Java :: java statements 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =