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.
23 lines
864 B
23 lines
864 B
import java.io.*;
|
|
|
|
public class ScoreAverage1 {
|
|
public static void main(String[] args) {
|
|
String line;
|
|
int sum = 0;
|
|
int count = 0;
|
|
try (BufferedReader br = new BufferedReader(new FileReader("score_empt.txt"))) {
|
|
while ((line = br.readLine()) != null) {
|
|
sum += Integer.parseInt(line);
|
|
count++;
|
|
}
|
|
double average = (double) sum / count;
|
|
System.out.println("Average score: " + average);
|
|
} catch (NumberFormatException e) {
|
|
System.out.println("Invalid number format in file: " + e.getMessage());
|
|
} catch (FileNotFoundException e) {
|
|
System.out.println("File not found: " + e.getMessage());
|
|
} catch (IOException e) {
|
|
System.out.println("An error occurred: " + e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
|