forked from sensei-thundercleese/closet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoDimArray.java
More file actions
66 lines (55 loc) · 1.9 KB
/
Copy pathTwoDimArray.java
File metadata and controls
66 lines (55 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// skeleton file for
// class TwoDimArray
// ...practice working with 2D arrays
public class TwoDimArray {
//postcond: prints each row of 2D integer array a on its own line
// uses a FOR loop
public static void print1( int[][] a ) {
// *** YOUR IMPLEMENTATION HERE ***
}
//postcond: prints each row of 2D integer array a on its own line
// uses a FOREACH loop
public static void print2( int[][] a ) {
// *** YOUR IMPLEMENTATION HERE ***
}
//postcond: returns sum of all items in 2D integer array a
public static int sum1( int[][] a ) {
// *** YOUR IMPLEMENTATION HERE ***
}
//postcond: returns sum of all items in 2D integer array a
// * uses helper fxn sumRow
public static int sum2( int [][] m ) {
// *** YOUR IMPLEMENTATION HERE ***
}
//postcond: returns sum of all items on row r of 2D integer array a
// uses a FOR loop
public static int sumRow( int r, int[][] a ) {
// *** YOUR IMPLEMENTATION HERE ***
}
//postcond: returns sum of all items on row r of 2D integer array a
// uses a FOREACH loop
public static int sumRow2(int r, int[][] m){
// *** YOUR IMPLEMENTATION HERE ***
}
public static void main(String [] args) {
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int [][] m1 = new int[4][2];
int [][] m2 = { {2,4,6}, {3,5,7} };
int [][] m3 = { {2}, {4,6}, {1,3,5} };
print1(m1);
print1(m2);
print1(m3);
print2(m1);
print2(m2);
print2(m3);
System.out.print("testing sum1...\n");
System.out.println("sum m1 : " + sum1(m1));
System.out.println("sum m2 : " + sum1(m2));
System.out.println("sum m3 : " + sum1(m3));
System.out.print("testing sum2...\n");
System.out.println("sum m1 : " + sum2(m1));
System.out.println("sum m2 : " + sum2(m2));
System.out.println("sum m3 : " + sum2(m3));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
}
}//end class TwoDimArray