forked from angiejones/java-programming
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAverageTestScores.java
More file actions
35 lines (26 loc) · 877 Bytes
/
Copy pathAverageTestScores.java
File metadata and controls
35 lines (26 loc) · 877 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
package chapter4;
import java.util.Scanner;
/*
* NESTED LOOPS:
* Find the average of each student's test scores
*/
public class AverageTestScores {
public static void main(String args[]){
//Initialize what we know
int numberOfStudents = 24;
int numberOfTests = 4;
Scanner scanner = new Scanner(System.in);
//Process all students
for(int i=0; i< numberOfStudents; i++){
double total = 0;
for(int j=0; j<numberOfTests; j++){
System.out.println("Enter the score for Test #" + (j+1));
double score = scanner.nextDouble();
total = total + score;
}
double average = total/numberOfTests;
System.out.println("The test average for student #" + (i+1) + " is " + average);
}
scanner.close();
}
}