-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathTwiceData.java
More file actions
30 lines (25 loc) · 804 Bytes
/
Copy pathTwiceData.java
File metadata and controls
30 lines (25 loc) · 804 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.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class TwiceData {
public static void main(String[] args) {
Scanner infile;
PrintWriter pw;
try {
infile = new Scanner(new File("nums.txt"));
pw = new PrintWriter("twice_nums.txt");
int inputNum;
while(infile.hasNext()) {
inputNum = infile.nextInt();
inputNum *= 2; //multiply by 2
pw.println(inputNum);
}//end while
infile.close();
pw.close();
}
catch(FileNotFoundException ex) {
System.out.println(ex.getMessage());
}//end try-catch
}//end main
}