-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathNamesAges.java
More file actions
35 lines (29 loc) · 1018 Bytes
/
Copy pathNamesAges.java
File metadata and controls
35 lines (29 loc) · 1018 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
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class NamesAges {
public static void main(String[] args) {
Scanner namesFile;
Scanner agesFile;
PrintWriter pw;
try {
namesFile = new Scanner(new File("student_names.txt"));
agesFile = new Scanner(new File("student_ages.txt"));
pw = new PrintWriter("names_ages.txt");
String tempName;
int tempAge;
while(namesFile.hasNext()) {
tempName = namesFile.nextLine();
tempAge = agesFile.nextInt();
pw.println(tempName + " is " + tempAge + " years old.");
}//end while
namesFile.close();
agesFile.close();
pw.close();
}
catch(FileNotFoundException ex) {
System.out.println(ex.getMessage());
}//end try-catch
}//end main
}