-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAverage.java
More file actions
30 lines (25 loc) · 798 Bytes
/
Average.java
File metadata and controls
30 lines (25 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class Average
{
int counter = 0;
int total = 0;
public Average()
{
try{
File numbers = new File("numbers.txt");
Scanner sc = new Scanner(numbers);
while(sc.hasNextLine()){
//System.out.println(sc.nextLine());
counter++;
if(sc.hasNextLine())
total += Integer.parseInt(sc.nextLine());
}
System.out.println("Lines : " + counter + " Total : " + total);
System.out.println("Average : " + total/counter);
}catch(IOException i){
System.out.println("Error : " + i.getMessage());
}
}
}