Question: A matrix is a two-dimensional array (it has both rows and columns). Instead of being just one row of length y , a matrix


A matrix is a two-dimensional array (it has both rows and columns). Instead of being just one row of length " y ", a matrix has " x " rows of length " y ". You declare a matrix with the following syntax: int[][]myMatrix=newint[rows][columns]; For this exercise, build a matrix out of input from Scanner. For example, for the input... 35434543543543 ...the first number on the first line gives you the number of rows (3), and the second number gives you the number of columns (4). The lines that follow are the matrix values. At the same time that you add values to your 2-D matrix, you should also add them to a 1-D ArrayList. Then, output the values as follows, by iterating through your ArrayList: 5,5,5,5,4,4,4,4,3,3,3,3, If the matrix (and ArrayList) are empty, print: "Empty!" Implementation hint: - Use a nested for loop to get input from the Scanner and fill your matrix. \begin{tabular}{l|l} AB & 5.19.1: LAB: Build a matrix \\ CTIVITY & 5. \end{tabular} 0/10 Matrix.java Load default template... 123456789101112131415imporimporpublipu} import java.util.Scanner; import java.util.Arraylist; public class Matrix \{ public static void main(String[] args) \{ Scanner scnr = new Scanner(System.in); /* Type your code here. Remember to call your 2-D array "myMatrix". */ Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
