|
1234567891011121314151617181920212223242526 |
- import java.util.Scanner;
- import java.util.ArrayList;
- import java.io.*;
-
- class Temperatur {
- private static double avg(ArrayList<Integer> nums) {
- double sum = 0;
- for (int n: nums) {
- sum += n;
- }
- return sum / nums.size();
- }
-
- public static void main(String[] args) throws FileNotFoundException {
- Scanner s = new Scanner(new File("temperatur.txt"));
- ArrayList<Integer> temps = new ArrayList<Integer>();
-
- while (s.hasNextLine()) {
- String num = s.nextLine()+" ";
- System.out.println("'"+num+"'");
- temps.add(Integer.parseInt(num));
- }
-
- System.out.println("Average temperature: "+avg(temps));
- }
- }
|