: Hey guys! I'm a sophormore in highschool and I have this whole java
: summer course thing I have to take care of. The course, which I
: regrettably failed to pay full attention to, is over, but I don't
: really feel like I learned alot (or anything).
:
: The thing is though, the teach left us with some random code
: problems which he left for us to solve. Here's one of them that I've
: been trying to figure out.
:
: In one class, create 3 matrices of 3x3 grids, matrix a, matrix b,
: and matrix c.
:
: Add the values of a to the values of b to create the values for c.
:
: Please randomly generate the numbers in a and b. (Between 0 and 20)
:
: a|--0--1--2-----b|--0--1--2-----c|--0--1--2
: 0|--1--2--3-----0|--10-11-12----0|--11-13-15
: 1|--4--5--6-----1|--13-14-15----1|--17-19-21
: 2|--7--8--9-----2|--16-17-18----2|--23-25-27
:
: (I'm using all those dashes because the spacing goes wacky
: otherwise, the dashes aren't supposed to be in the program)
:
: so the numbers in grid a are supposed to be all random, don't have
: to be only 1 digit, as long as its between 1-20. similarly with grid
: b, the numbers don't have to be 2 digits. and every value in c is
: the sum of the corresponding values in a and b.
:
: any ideas?
:
: and I'm supposed to print out a picture that looks something like
: that (don't need all the lines and dashes though)
:
: Thanks.
:
:
This requires several nested for-loops. 1 for each a and b. 1 to add them together to form c. And 1 to display each matrix separately. Look up the for-loop in your notes/book and then start coding.
I would suggest that you create a method to create a matrix, one to perform the addition and one to display a given matrix.
Here's a start:
public class MatrixAddition {
public int[][] createMatrix(int rows, int columns) {
}
public int[][] addMatrix(int[][] a, int[][] b) {
}
public void display(int[][] matrix) {
}
}