-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathioReader.java
More file actions
61 lines (29 loc) · 885 Bytes
/
ioReader.java
File metadata and controls
61 lines (29 loc) · 885 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package javaScribbles;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class ioReader {
public static void main(String[] args) {
int grade;
String name;
int counter = 0;
double average=0;
try {
File datafile = new File("data.txt");
Scanner input = new Scanner("data.txt"); // Scanner object to read file
System.out.printf("Name \t Grade \n");
while(input.hasNext()) {
name = input.next();
grade = input.nextInt();
counter++;
average = grade / counter;
System.out.printf(" Average Grade : %2f", average );
}
}
catch (FileNotFoundException ex) {
System.out.println("data.txt : oops, FileNotFoundException caught");
ex.printStackTrace();
}
}
}
//end of class