Java Program Your program should use 2D arrays to implement simple matrix operations. Your program should do the following: • Read the number of rows and columns of a matrix M1 from the user. Use an input validation loop to make sure the values are greater than 0. • Read the elements of M1 in row major order • Print M1 to the console; make sure you format as a matirx • Repeat the previous steps for a second matrix M2 • Create a matrix M3 that is the transpose of M1 and print it to the console • Check if M1 and M2 can be added (should have the same dimensions). If possible, add M1 and M2 and print the result to the console. Otherwise print an error message. • Extra credit: Multiply M1 and M2 if possible and print to the console. If the matrices cannot be multiplied, print an error message. Implementation requirements: • Use a helper method for reading a positive integer using an input validation loop. • Use a helper method for printing a matrix. Your helper methods should be private and static, and called in the main method.
Java
Your program should use 2D arrays to implement simple matrix operations.
Your program should do the following:
• Read the number of rows and columns of a matrix M1 from the user. Use an input validation
loop to make sure the values are greater than 0.
• Read the elements of M1 in row major order
• Print M1 to the console; make sure you format as a matirx
• Repeat the previous steps for a second matrix M2
• Create a matrix M3 that is the transpose of M1 and print it to the console
• Check if M1 and M2 can be added (should have the same dimensions). If possible, add M1
and M2 and print the result to the console. Otherwise print an error message.
• Extra credit: Multiply M1 and M2 if possible and print to the console. If the matrices cannot
be multiplied, print an error message.
Implementation requirements:
• Use a helper method for reading a positive integer using an input validation loop.
• Use a helper method for printing a matrix.
Your helper methods should be private and static, and called in the main method.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images