Advertisement
cd62131

Print Temperature Average so Primitive

Dec 11th, 2013
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.51 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class Average {
  4.   public static void main(String args[]) {
  5.     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  6.     int i = 0;
  7.     double sum = 0.0;
  8.     double num;
  9.     double ave = 0.0;
  10.     String str;
  11.     try {
  12.       while ((str = br.readLine()) != null) {
  13.         num = Double.parseDouble(str);
  14.         i++;
  15.         sum += num;
  16.       }
  17.     }
  18.     catch (Exception e) {
  19.     }
  20.     ave = sum / i;
  21.     System.out.println("平均 = " + ave);
  22.   }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement