Advertisement
Guest User

Complex Matrix java

a guest
Feb 27th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.12 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package mid;
  7.  
  8. import java.util.Random;
  9. import java.util.Scanner;
  10.  
  11. /**
  12.  *
  13.  * @author NEW
  14.  */
  15.  
  16. class Complex{
  17.    
  18.    
  19.     int real,img;
  20.     Complex(){
  21.        
  22.         real = 0;
  23.         img = 0;
  24.     }
  25.     Complex (int x,int y){
  26.         real = x ;
  27.         img = y ;
  28.     }
  29.     void GeneratComplex(int x,int y){
  30.         real = x;
  31.         img = y ;
  32.        
  33.     }
  34.    
  35.     void DisplayComplexMatrix(){
  36.        
  37.         System.out.print(real+" + "+img+"i  ");
  38.     }
  39.    
  40.  
  41.    
  42.    
  43. }
  44.  
  45. class Matrix{
  46.    
  47.     int row,col;
  48.    
  49.     Complex  data [][] = new Complex [10][10];
  50.    
  51.     Matrix (int x){
  52.         row =col =x;
  53.     }
  54.     Matrix (int x,int y){
  55.         row=x;
  56.         col =y;
  57.         for (int i =0 ; i <data.length; i++){
  58.             for (int j =0 ; j<data[i].length; j++){
  59.                 data[i][j] = new Complex();
  60.             }
  61.            
  62.         }
  63.     }
  64.    
  65.     void RandomGenerated(){
  66.         Random rand = new Random();
  67.         for(int i = 0 ; i <row; i++){
  68.             for (int j = 0; j <col; j++){
  69.                
  70.                 data[i][j].GeneratComplex(rand.nextInt(10),rand.nextInt(5));
  71.             }
  72.         }
  73.     }
  74.    
  75.     void DisplayMatrix(){
  76.          for(int i = 0 ; i <row; i++){
  77.             for (int j = 0; j <col; j++){
  78.                
  79.                 data[i][j].DisplayComplexMatrix();
  80.             }
  81.             System.out.println(" ");
  82.         }
  83.     }
  84.    
  85. }
  86.  
  87. public class Mid {
  88.  
  89.     /**
  90.      * @param args the command line arguments
  91.      */
  92.     public static void main(String[] args) {
  93.         // TODO code application logic here
  94.         int row = 0,col=0;
  95.         Scanner read = new Scanner(System.in);
  96.         System.out.println("Enter Row and Col : ");
  97.         row =read.nextInt();
  98.         col = read.nextInt();
  99.        
  100.         Matrix m1 = new Matrix (row,col);
  101.        
  102.         m1.RandomGenerated();
  103.         m1.DisplayMatrix();
  104.     }
  105.    
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement