Question: Write a Java program for a 2 x 2 matrix, the program will be using methods to add 2 matrices and find the inverse of
Write a Java program for a x matrix, the program will be using methods to add
matrices and find the inverse of a matrix. Submit the program with format
LastnameFirstnameHWjava
Create Method with no parameters: that prompts the user to input values for a
x matrix.
It initializes a x matrix and assigns values to it based on user input. Method
Returns a matrix
Create Display Method NO return value: Takes a D array matrix as an
argument and prints its elements in matrix form.
Create addition Matrix Method: that Takes two D arrays matrices as
arguments.
Adds corresponding elements of the matrices and stores the result in a new
matrix. Method returns the resulting matrix
Create the inverse matrix Method that will return a matrix: Takes a D array
matrix as an argument.
Declare a boolean variable assign to true
Calculates the inverse of the x matrix using the formula for the inverse of a
x matrix:
Swaps the diagonal elements.
Negates the offdiagonal elements.
Calculates the determinant
Calculate the reciprocal of the determinant
A temporary variable temp is declared for swapping elements.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
