Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package mid;
- import java.util.Random;
- import java.util.Scanner;
- /**
- *
- * @author NEW
- */
- class Complex{
- int real,img;
- Complex(){
- real = 0;
- img = 0;
- }
- Complex (int x,int y){
- real = x ;
- img = y ;
- }
- void GeneratComplex(int x,int y){
- real = x;
- img = y ;
- }
- void DisplayComplexMatrix(){
- System.out.print(real+" + "+img+"i ");
- }
- }
- class Matrix{
- int row,col;
- Complex data [][] = new Complex [10][10];
- Matrix (int x){
- row =col =x;
- }
- Matrix (int x,int y){
- row=x;
- col =y;
- for (int i =0 ; i <data.length; i++){
- for (int j =0 ; j<data[i].length; j++){
- data[i][j] = new Complex();
- }
- }
- }
- void RandomGenerated(){
- Random rand = new Random();
- for(int i = 0 ; i <row; i++){
- for (int j = 0; j <col; j++){
- data[i][j].GeneratComplex(rand.nextInt(10),rand.nextInt(5));
- }
- }
- }
- void DisplayMatrix(){
- for(int i = 0 ; i <row; i++){
- for (int j = 0; j <col; j++){
- data[i][j].DisplayComplexMatrix();
- }
- System.out.println(" ");
- }
- }
- }
- public class Mid {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- int row = 0,col=0;
- Scanner read = new Scanner(System.in);
- System.out.println("Enter Row and Col : ");
- row =read.nextInt();
- col = read.nextInt();
- Matrix m1 = new Matrix (row,col);
- m1.RandomGenerated();
- m1.DisplayMatrix();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement