Home Work Questions - 2 dimensional arrays (matrix)

Use :
private int[][] m = new int[4][3]; // your code should work for any size

1. Write a function that will let you enter numbers into a 2 dimensional array.

public void enter()

2 Write a function that will print out a matrix in table form.

public void print()

3. Write a function that will give you the sum of the numbers in a matrix.

public int sum( )

4. Write a function that will give you the sum of the numbers in a row in a matrix.

public int rowsum( int row)

5. Write a function that will return the smallest number in a matrix.

int smallest()

6. Write a function that will print out the numbers in the diagonal in a square matrix.

public void diagsum()

7. Write a function that will fill a matrix with random numbers between 1 and 100. public void fill()

8. Write a function that will print out numbers in a particular column.

public void printcolumn(int col)

9. Write a function that will switch every other row in a matrix.

public void switch()

10. Write a function that will return the sum of the numbers in the top half of a matrix.

public int getsum()

11. Write a function the will return the average of the numbers in a matrix.

public double avg()

12. Write a function that will print out all the odd numbers in the matrix that have all odd numbers or borders all around it. (east, north, south, east)

publicvoid printodd()

13. Write a function that will return the row that has the largest sum

public int row()

14.Write a function that will return the sum of the numbers in the outside of the matrix.

public int bordersum()

15. Write a function that will return true if a row is in ascending order.

public boolean rowinorder( int row)

16. Write a function that will return true if matrix is in order. You may call the function written above. In addition in order for matrix to be in order, each element in the last column of a row must be smaller than first element in next row.

public boolean matrixinorder()

// you should call rowinorder function for this but there is more to do

17. Write a function that will return true if there are no zeroes in a matrix.

public boolean nozeroes()

18. Write a function that will return sum of matrix. You must call function written in number 4.

public int matrixsum()

19. Write a function that will reverse the numbers in a row.

public void fliprow( int r)

20. Write a function that will flip a matrix so that you get the mirror image of it.

2 5 6 6 5 2 7 9 3 -> 3 9 7 4 7 8 8 7 4

public void flip()

// hint you should call function fliprow for this.

21. Write a function that will return the sum of the numbers in the diagonal that goes from right to left.
public int rightdiagsum()

22. Write a method that will print out all the blocks in a city that do not have fire hydrants and do not have hydrants to its North, South, East or West.

private boolean[][] city = new boolean[30][40];

Any block that holds a hydrant has been set to True

public void printBlocksWithoutHydrants()


23. Write a class that will fill a 4x3 matrix with random numbers between 1 and 100. Run it until you get a matrix that is ascending order. How many times did it take? Then run the simulation one million times and get the average of how many times the matrix had to be filled to get an ordered one.

24. Write a function that will change any even number in the matrix to the number to the left of it. If there is no number to the left change it to a 1. Process in row - column order.