Advertisement
cd62131

Print Temperature Avarage

Dec 7th, 2013
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.72 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Scanner;
  5.  
  6. public class TemperatureAvarage {
  7.   public static void main(String[] args) {
  8.     Scanner in = null;
  9.     try {
  10.       in = new Scanner(new File("kion.txt"));
  11.     }
  12.     catch (Exception e) {
  13.     }
  14.     int days = 0;
  15.     List<Double> temperature = new ArrayList<Double>();
  16.     while (in.hasNextLine()) {
  17.       double temp = .0;
  18.       try {
  19.         temp = new Double(in.nextLine());
  20.       }
  21.       catch (Exception e) {
  22.       }
  23.       temperature.add(temp);
  24.       days++;
  25.     }
  26.     double sum = .0;
  27.     for (Double temp: temperature) {
  28.       sum += temp;
  29.     }
  30.     System.out.println("平均: " + sum / days);
  31.   }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement