Question

# Perform the following tasks on the matrix:a) Display the original matrix.b) Calculate the decimal equivalent for each row and display as per the format given below.

```				```
Test your program for the following data and some random data:
Example 1:

INPUT:

M = 1
N = 3
Enter elements for row 1: 1 4 4

OUTPUT:

Filled Matrix:

1 4 4
Decimal Equivalent:

100

Example 2:

INPUT:

M = 3
N = 4

Enter elements for row 1: 1 1 3 7
Enter elements for row 2: 2 1 0 6
Enter elements for row 3: 0 2 4 5

OUTPUT:

Filled Matrix:

1 1 3 7
2 1 0 6
0 2 4 5

Decimal Equivalent:

607
1094
165

Example 3:
INPUT:

M = 3
N = 3
Enter elements for row 1: 2 4 8

OUTPUT:

Invalid Input.

Example 4:
INPUT:

M = 4
N = 6
OUTPUT:
Out of range.
```
```

# Share code with your friends

Code

```				```
import java.util.Scanner;
class OctalToDecimal
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a[][];
int m=0,n=0,decimal=0,product=0,i=0,j=0;
System.out.print("M = ");
m = sc.nextInt();
System.out.print("N = ");
n = sc.nextInt();

if(m < 1 || m > 9 || n < 3 || n > 5)
{
System.out.println("Out of range.");

}

else
{
a = new int[m][n];
for(i = 0; i < m; i++)
{
System.out.println("Enter elements for row " + (i + 1) + ":");
for(j = 0; j < n; j++)
{
a[i][j] = sc.nextInt();
if(a[i][j] < 0 || a[i][j] > 7)
{
System.out.println("Invalid Input.");
return;
}
}
}
System.out.println("Filled Matrix:");
for(i = 0; i < m; i++)
{
for(j = 0; j < n; j++)
{
System.out.print(a[i][j] + " ");
}
System.out.println();
}

System.out.println("Decimal Equivalent:");
for(i = 0; i < m; i++)
{
decimal = 0;
product = n - 1;
for(j = 0; j < n; j++)
{
decimal += a[i][j] * (int)Math.pow(8, product);
product--;
}
System.out.println(decimal);
}
}
}
}

```
```

## Coding Store

Sale ### Mastering String

50
Sale 150
Sale 200
Sale ### Mastering Recursion

50
Sale ### Mastering Numbers

50
Sale ### Mastering Matrix

50
Sale ### Mastering Array

50
Sale ### ISC QUESTION PAPERS WITH SOLUTION(PROGRAMMING ONLY)

50
Sale 50