saykotislam

201-15-13993_9

Feb 21st, 2021
57
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package lab;
  2.  
  3. import java.util.Scanner;
  4. class Complex{
  5.     void sum(int a,int b,int c,int d)
  6.     {
  7.         int i,r;
  8.         r=a+c;
  9.         i=b+d;
  10.         System.out.print("Sum = "+r);
  11.         if(i>=0)System.out.print(" + ");
  12.        
  13.         System.out.println(i+" i");
  14.     }
  15.    
  16.     void difference(int a,int b,int c,int d)
  17.     {
  18.         int i,r;
  19.         r=a-c;
  20.         i=b-d;
  21.         System.out.print("difference = "+r);
  22.         if (i>=0)System.out.print(" + ");
  23.        
  24.         System.out.println(i+" i");
  25.     }
  26.    
  27.     void product(int a,int b,int c,int d)
  28.     {
  29.         int i,r;
  30.         r=a*c-b*d;
  31.         i=b*c+a*d;
  32.         System.out.print("product = "+r);
  33.         if (i>=0)System.out.print(" + ");
  34.        
  35.         System.out.println(i+" i");
  36.     }
  37.    
  38. }
  39.  
  40. public class objc {
  41.  
  42.    
  43.     public static void main(String[] args) {
  44.         Complex newc=new Complex();
  45.         Scanner input=new Scanner(System.in);
  46.        
  47.        
  48.         int r1,i1,r2,i2;
  49.         System.out.println("Enter Value of realnumber part of 1st complex number");
  50.         r1=input.nextInt();
  51.         System.out.println("Enter Value of imaginary part of 1st complex number");
  52.         i1=input.nextInt();
  53.        
  54.         System.out.println("Enter Value of realnumber part of 1st complex number");
  55.         r2=input.nextInt();
  56.         System.out.println("Enter Value of imaginary part of 1st complex number");
  57.         i2=input.nextInt();
  58.        
  59.         newc.sum(r1,i1,r2,i2);  
  60.         newc.difference(r1,i1,r2,i2);
  61.     }
  62. }
RAW Paste Data