Advertisement
thefinn93

CSS161 Averages

Feb 11th, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. package average;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.util.Scanner;
  6.  
  7. public class Average {
  8.     public static void main(String[] args) throws FileNotFoundException {
  9.         Scanner in = new Scanner(new File("averageme.txt"));
  10.         int total = 0;
  11.         int average = 0;
  12.         int i = 0;
  13.         while(in.hasNextInt()) {
  14.             int a = in.nextInt();
  15.             total = total + a;
  16.             i++;
  17.             average = total/i;
  18.             System.out.println("int " + i + " is\t" + a + "\tnew average is " + average);
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement