Instructions
Please log into cs.bridgewater.edu. Navigate to the csci101/hw/apr12 directory in your git repository. Write a program in a file named Practice.java
that satisfies the following program specifications. When finished, push your code to GitHub.
Program Specification
Write a method named printMatrix
that takes a 2D array (matrix) of integers as an argument and prints the elements in the matrix to the screen with each row of elements appearing on a separate line.
Write a second method, also named printMatrix that takes a 2D array (matrix) of characters as an argument and prints the elements in the matrix to the screen with each row of elements appearing on a separate line.
In main()
please do the following.
-
- Creates a 3 x 3 2D array of characters named
matrix1
with the following values:
c a t
a t e
t e a - Print the contents of
matrix1
using theprintMatrix
method. - Create a 3 x 3 2D array of integers named
matrix2
. Using nested for-loops initializes the 2D array with following values:
1 1 1
1 1 1
1 1 1 - Print the contents of
matrix2
using theprintMatrix
method. - Change the element at row 1, column 1 in
matrix2
to the value 7. - Print the contents of
matrix2
using theprintMatrix
method. - Write a fragment of code that creates a 3 x 3 2D array of characters named
matrix3
and using nested for-loops populate matrix3 with the values inmatrix1
(in the same order). - Print the contents of
matrix3
using theprintMatrix
method. - Get the value of the element at row 1, column 1 in
matrix3
and store it in a variable namedelm
. Print the value of elm to the screen.
- Creates a 3 x 3 2D array of characters named
© 2021 – 2024, Eric. All rights reserved.