Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ANDY ZHANG, 2
- import java.util.*;
- import java.io.*;
- public class NumbersAverage
- {
- // Scanner sc = new Scanner(new File("<path-to-file>"));
- // remember to import your classes
- // import java.util.io.*;
- // lookup scanner documentation
- public long average()
- {
- //Scanner in = new Scanner(System.in);
- int count = 0;
- long total = 0;
- long finalAverage = 1;
- try{
- Scanner in = new Scanner(new File("C:\\numbers.txt"));
- while(in.hasNextLine())
- {
- total += in.nextInt();
- count++;
- }
- } catch (Exception e) {
- //finalAverage = (long)(total/count);
- //return finalAverage;
- }
- finalAverage = (long)(total/count);
- return finalAverage;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement