You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
999 B
31 lines
999 B
import java.io.BufferedReader;
|
|
import java.io.FileReader;
|
|
import java.io.IOException;
|
|
|
|
public class ScoreCalculatorAfter {
|
|
public static void main(String[] args) {
|
|
int sum = 0;
|
|
int count = 0;
|
|
|
|
try (BufferedReader br = new BufferedReader(new FileReader("scores.txt"))) {
|
|
String line;
|
|
while ((line = br.readLine()) != null) {
|
|
try {
|
|
sum += Integer.parseInt(line);
|
|
count++;
|
|
} catch (NumberFormatException e) {
|
|
System.err.println("Invalid number format: " + line);
|
|
}
|
|
}
|
|
} catch (IOException e) {
|
|
System.err.println("Error reading file: " + e.getMessage());
|
|
}
|
|
|
|
if (count > 0) {
|
|
double average = (double) sum / count;
|
|
System.out.println("Average score: " + average);
|
|
} else {
|
|
System.out.println("No valid scores found.");
|
|
}
|
|
}
|
|
}
|