Home
Site Map
Useful Tools
Graphing Calc

Scientific Calculator

2-D Array Projects 1

Add the following Methods to a class called ArrayFun2D
public void print(int[][] arr)

Description: This method prints each element in the array. This will be a useful method when you are debugging your code and want to test it out to see if it works.

Method Call return value(hex form)
print({{1,2} , {3,4}, { 5, 6 } } ) 1
2
3
4
5
6
public int sum(int[][] arr)

Description: This method returns the sum of all elements in the array

Method Call return value(hex form)
print({{1,2} , {3,4}, { 5, 6 } } ) 21 ( ie 1+2+3+4+5+6)
public void printRow(int[][] arr, int row)

Description: This method prints all elements in row

Method Call return value(hex form)
printRow({{1,2} , {3,4}, { 5, 6 } } , 1 ) 3
4
printRow( { 5 , 6} , {7, 12, 13 , 5 }, { 5, 6 ,0} } , 2 ) 5
6
0
public void printCol(int[][] arr, int col)

Description: This method prints all elements in col. Precondition: Assume that col is always a valid column in arr. +1 extra credit: research try{}cathc() statements to catch any ArrayIndexOutOfBoundsException and handle situtions where col is not always valid.

Method Call return value(hex form)
printCol({{1,2} , {3, 4}, { 5, 6 } } , 1 ) 2
4
6
printCol( { 5 , 6} , {7, 12, 13 , 5 }, { 12, 6 ,0} } , 0 ) 5
7
12
public int maxVal(int[][] arr, int row)

Description: This method returns the value of the largest number in the given row

Method Call return value(hex form)
maxVal({{1,2} , {3,4}, { 5, 6 } } , 1 ) 4
maxVal( { 5 , 6} , {7, 12, 13 , 5 }, { 5, 6 ,0} } , 3 ) 6
public int maxVal(int[][] arr, int col)

Description: This method returns the value of the largest number in the given col

Method Call return value(hex form)
maxVal({{1,2} , {3,4}, { 5, 6 } } , 0 ) 5
public int[][] changeValues(int[][] table, int val)

Description: This method returns the array with all elements set to val

changeValues(table, 5)

Original Array
1 2
3 4
5 6
Returned Array
5 5
5 5
5 5
**public int[][] invertValues(int[][] matr)

Description: This method returns the paramater with its values 'inverted'

Original Array
1 2
3 4
5 6
Returned Array
6 5
4 3
2 1
Sitemap