-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayMethods.java
58 lines (56 loc) · 1.24 KB
/
ArrayMethods.java
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
package Gazzayeatman.PR282.JavaControlExcercises;
public class ArrayMethods {
public ArrayMethods() {
// TODO Auto-generated constructor stub
}
public static int arrayMinValue(int[] a){
int result = 200;
int length = a.length;
for (int i = 0; i < length; i++){
if (a[i] < result){
result = a[i];
}
}
return result;
}
public static int arrayMaxValue(int[] a){
int result = 0;
int length = a.length;
for (int i = 0; i < length; i++){
if (a[i] > result){
result = a[i];
}
}
return result;
}
public static int arraySum(int[] a){
int result = 0;
int length = a.length;
for (int i = 0; i < length; i++){
result += a[i];
}
return result;
}
public static int arraySumSquared(int[] a){
int result = 0;
int length = a.length;
for (int i = 0; i < length; i++){
result += a[i] * a[i];
}
return result;
}
public static String displayIntArray(int[] rayRay){
String result = "";
for (int i = 0; i < rayRay.length; i++){
result += " " + rayRay[i];
}
return result;
}
public static String displayCharArray(char[] rayRay){
String result = "";
for (int i = 0; i < rayRay.length; i++){
result += rayRay[i];
}
return result;
}
}