Write a program to get the inverse of 2 x 2 matrix with proper error checking.
Input (Two Dimensional matrix) | Output (Two Dimensional matrix) |
---|---|
20 45 |
0.5 -4.5 |
-1 2 |
-7.0 -2.0 |
25 20 |
null |
{}(EMPTY ARRAY) |
null |
null |
null |
class AdvanceInverseOf2X2Matrix
{ public static void main(String s[])
{
int input[][] = {{20, 45}, {2, 5}};
double output[][] = getInverse(input);
if (output != null) {
for (double[] array1d : output) {
for (double element : array1d) {
System.out.print(element + " ");
}
System.out.println();
}
} else {
System.out.println("Inverse of matrix should not be performed due to invalid input data.");
}
}
public static double[][] getInverse(int matrix[][]) {
//Write code here to get the inverse of given 2 x 2 matrix and return the result.
}
public static int getDeterminant(int matrix[][]) {
int result = 0;
//Write code here to get the determinant of given 2 x 2 matrix.
return result;
}
}
Topic: Learn Arrays And Loops