-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrades.java
More file actions
32 lines (32 loc) · 975 Bytes
/
Copy pathGrades.java
File metadata and controls
32 lines (32 loc) · 975 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
import java.io.*;
import java.util.Scanner;
public class Grades{
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
double[] grades = new double[8];
for (int i = 0; i < 8; i++) {
System.out.print("Enter grade for student " + (i + 1) + ": ");
grades[i] = scanner.nextDouble();
}
DataOutputStream output = new DataOutputStream(new FileOutputStream("grades.txt"));
for (double grade : grades) {
output.writeDouble(grade);
}
output.close();
DataInputStream input = new DataInputStream(new FileInputStream("grades.txt"));
double highestGrade = Double.MIN_VALUE;
double lowestGrade = Double.MAX_VALUE;
while (input.available() > 0) {
double grade = input.readDouble();
if (grade > highestGrade) {
highestGrade = grade;
}
if (grade < lowestGrade) {
lowestGrade = grade;
}
}
input.close();
System.out.println("Highest grade: " + highestGrade);
System.out.println("Lowest grade: " + lowestGrade);
}
}