import java.util.Scanner;
class OctalMatrix
{
int A[][],m,n; //m and n are rows and columns
OctalMatrix(int m,int n)
{
this.m=m;
this.n=n;
A = new int[m][n];
}
void octaltoDec()
{
Scanner sc=new Scanner(System.in);
if((m<0 || m>10) && (n<2 || n>6))
{
System.out.println("Invalid Row or Column");
return;
}
else
{
//Enter the values into the matrix
System.out.println("Enter the octal numbers into the matrix:");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
int m = sc.nextInt();
if(m>=0 && m<=7)
{
A[i][j]=m;
}
else{
System.out.println("Invalid Input");
return;
}
}
}
//Converting each row to octal number
System.out.println("Converting each row to octal:");
for(int i=0;i<m;i++)
{
int s=0;
int p=n;
for(int j=0;j<n;j++)
{
s=s+A[i][j]*(int)Math.pow(8,p-1);
p=p-1;
System.out.print(A[i][j]+" ");
}
System.out.print(" Decimal:"+s);
System.out.println();
}
}
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the rows and columns:");
int m=sc.nextInt();
int n=sc.nextInt();
OctalMatrix ob = new OctalMatrix(m,n);
ob.octaltoDec();
}
}
class OctalMatrix
{
int A[][],m,n; //m and n are rows and columns
OctalMatrix(int m,int n)
{
this.m=m;
this.n=n;
A = new int[m][n];
}
void octaltoDec()
{
Scanner sc=new Scanner(System.in);
if((m<0 || m>10) && (n<2 || n>6))
{
System.out.println("Invalid Row or Column");
return;
}
else
{
//Enter the values into the matrix
System.out.println("Enter the octal numbers into the matrix:");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
int m = sc.nextInt();
if(m>=0 && m<=7)
{
A[i][j]=m;
}
else{
System.out.println("Invalid Input");
return;
}
}
}
//Converting each row to octal number
System.out.println("Converting each row to octal:");
for(int i=0;i<m;i++)
{
int s=0;
int p=n;
for(int j=0;j<n;j++)
{
s=s+A[i][j]*(int)Math.pow(8,p-1);
p=p-1;
System.out.print(A[i][j]+" ");
}
System.out.print(" Decimal:"+s);
System.out.println();
}
}
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the rows and columns:");
int m=sc.nextInt();
int n=sc.nextInt();
OctalMatrix ob = new OctalMatrix(m,n);
ob.octaltoDec();
}
}