forked from Denisolt/CSCI-160
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathint2DArray.java
More file actions
93 lines (87 loc) · 2.59 KB
/
int2DArray.java
File metadata and controls
93 lines (87 loc) · 2.59 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//Denisolt Shakhbulatov
//11.16.2015
public class int2DArray
{
public static void main(String[] args)
{
int[][] iarray = { { 2,1,9}, {7,3,4}, { 5,6,8} };
System.out.println("Processing iarray.");
System.out.println("Total : " + getTotal(iarray));
System.out.println("Average : " + getAverage(iarray));
for (int r =0; r < iarray.length; r++)
{
System.out.println("Total of row " +r+ " : "+ getRowTotal(iarray,r));
}
for (int c =0; c < iarray.length; c++)
{
System.out.println("Total of col " +c+ " : "+ getColTotal(iarray,c));
}
for (int r =0; r < iarray.length; r++)
{
System.out.println("Highest in row " +r+ " : "+ getHighestinRow(iarray,r));
}
for (int r =0; r < iarray.length; r++)
{
System.out.println("Lowest in row " +r+ " : "+ getLowestinRow(iarray,r));
}
}
public static int getTotal(int[][] iarray)
{
int total = 0;
for (int row = 0; row < iarray.length; row++)
{
for (int col = 0; col < iarray[row].length; col++)
total += iarray[row][col];
}
return total;
}
public static double getAverage(int[][] iarray)
{
int total = 0;
for (int row = 0; row < iarray.length; row++)
{
for (int col = 0; col < iarray[row].length; col++)
total += iarray[row][col];
}
double average = total/(3*iarray.length);
return average;
}
public static int getRowTotal(int[][] iarray, int row)
{
int total = 0;
for (int r = 0; r < iarray[row].length; r++)
{
total += iarray[row][r];
}
return total;
}
public static int getColTotal(int[][] iarray, int col)
{
int total = 0;
for (int c = 0; c < iarray.length; c++)
{
total += iarray[c][col];
}
return total;
}
public static int getHighestinRow(int [][] iarray, int row)//METHOD FIND HIGHEST
{
int highest = iarray[row][0];
for (int i=1; i<iarray.length; i++)
{
if (iarray[row][i]>highest)
highest = iarray[row][i];
}
return highest;
}
public static int getLowestinRow(int [][] iarray, int row)//METHOD FIND LOWEST
{
int lowest = iarray[row][0];
for (int i=1; i<iarray.length; i++)
{
if (iarray[row][i]<lowest)
lowest = iarray[row][i];
}
return lowest;
}
}