You are on page 1of 3

import java.util.

*;

class matrix

public static void main(String args[])

double d=0.0;

Scanner sc=new Scanner(System.in);

System.out.println("enter m*n");

int p=0,q=0,x=0,s=0,y=1;

int M=sc.nextInt();//input for rows

int N=sc.nextInt();//input for columns

if((M<0||M>10)&&(N<2||N>6))//condition for rows and columns

System.out.println("OUT OF RANGE");

else

int a[][]=new int[M][N];

int b[]=new int[1000];

int c[]=new int[1000];

for(int i=0;i<M;i++)

for(int j=0;j<N;j++)

a[i][j]=sc.nextInt();//to input elements in the array

for(int i=0;i<M;i++)

for(int j=0;j<N;j++)

{
b[p]=a[i][j];//elements of the row in another array

p++; //counts no of elements in each row.

for(int i=0;i<M;i++)

for(int j=0;j<N;j++)

d=a[i][j]*Math.pow(8,N-y);//calculation of the decimal equivalent

s=(int)d;

x=x+s;

y++;

c[q]=x; //stores the decimal equivalent in another array.

q++;

y=1;

x=0;

System.out.println("FILLED MATRIX"+"\t\t"+"DECIMAL EQU");

for(int i=0;i<M;i++)

for(int j=0;j<N;j++)

System.out.print(a[i][j]+" "); //prints the row elements

System.out.println();

for(int j=0;j<q;j++)

System.out.print("\t\t\t"+c[j]); //prints it's decimal equivalent


System.out.println();

/*

M=1

N=3

ENTER ELEMEMTS FOR ROW 1: 1 4 4

FILLED MATRIX DECIMAL EQUIVALENT

1 4 4 100

*/

You might also like