-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGradeCount.java
More file actions
35 lines (30 loc) · 944 Bytes
/
GradeCount.java
File metadata and controls
35 lines (30 loc) · 944 Bytes
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
import java.util.Scanner;
import java.util.Arrays;
public class GradeCount {
static double[] scores = {9, 22, 3, 4};
//I want: a method that caculates the number of students in the given grade.
public static void main(String args[]) {
//setup
Scanner in = new Scanner(System.in);
String grade = in.nextLine();
int students = sum(grade);
System.out.println("The number of students with grade " + grade + " is: " + students);
}
public static int sum(String grade) {
int A = 0;
int B = 0;
double[] numbers = Arrays.copyOf(scores, scores.length);
for (int i = 0; i < numbers.length; i++) {
if (numbers[i] < 10) {
A ++;
} else {
B ++;
}
}
if (grade.equals("A")) {
return A;
} else {
return B;
}
}
}