Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class TemperatureAvarage {
- public static void main(String[] args) {
- Scanner in = null;
- try {
- in = new Scanner(new File("kion.txt"));
- }
- catch (Exception e) {
- }
- int days = 0;
- List<Double> temperature = new ArrayList<Double>();
- while (in.hasNextLine()) {
- double temp = .0;
- try {
- temp = new Double(in.nextLine());
- }
- catch (Exception e) {
- }
- temperature.add(temp);
- days++;
- }
- double sum = .0;
- for (Double temp: temperature) {
- sum += temp;
- }
- System.out.println("平均: " + sum / days);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement