-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray.java
More file actions
67 lines (47 loc) · 1.35 KB
/
Array.java
File metadata and controls
67 lines (47 loc) · 1.35 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
import java.util.Scanner;
public class Array {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
int[] arrayNumbers = new int[10];
for(int i = 0; i < arrayNumbers.length; i++) {
System.out.print("Enter grades [" + i + "] : ");
arrayNumbers[i] = console.nextInt();
}
console.close();
getAverage(arrayNumbers);
getMax(arrayNumbers);
getMin(arrayNumbers);
getDisplay(arrayNumbers);
}
public static void getAverage(int[] myArray) {
double ave = 0;
for(int j = 0; j < myArray.length; j++) {
ave = ave + myArray[j];
}
ave = ave /myArray.length;
System.out.println("The average is: " + ave);
}
public static void getMax(int[] myArray){
int max = 0;
for(int i = 0; i < myArray.length; i ++) {
if(myArray[i] > max) {
max = myArray[i];
}
}
System.out.println("The highest grade is: " + max);
}
public static void getMin(int[] myArray) {
int min = myArray[0];
for(int i = 0; i < myArray.length; i++) {
if(myArray[i] < min) {
min = myArray[i];
}
}
System.out.println("The lowest grade is: " + min);
}
public static void getDisplay(int[] myArray) {
for(int x = 0; x < myArray.length; x++) {
System.out.println("Grade [" + x + "] : " + myArray[x]);
}
}
}