-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintTwice.java
More file actions
65 lines (55 loc) · 1.37 KB
/
PrintTwice.java
File metadata and controls
65 lines (55 loc) · 1.37 KB
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
62
63
64
import java.util.Scanner;
import java.io.FileNotFoundException;
import java.io.File;
public class PrintTwice {
public class Task {
private int areacode = 0;
Scanner input;
String value = "";
String [] fileData;
public Task() {
areacode = 0;
input = new Scanner(System.in);
fileData = new String[10];
}
}
public void runIt() {
tryCatchIt();
int i = 0;
while (input.hasNext () ) {
//use an array of String
value = input. nextLine () ;
System.out.println(value) ;
fileData[i++] = value;
}
input.close () ;
//print out array using a loop
System.out.println("=== printing fileData ===");
for(int j=i-1;j>=0; j--) {
System.out.println(fileData[j]) ;
}
}
public void tryCatchIt() {
File inFile = new File("input.txt");
String inFileName = "input.txt";
value = ""; //field variable
input = null; //field variable
try {
input = new Scanner(inFile);
}
catch (FileNotFoundException e) {
System.err.println ("Cannot find " + inFileName + " file.");
System.exit(1);
}
}
public static void main(String[] args) {
PrintTwice a = new PrintTwice();
a.run();
}
public void run() {
Task t = new Task();
//t.method1();
//t.method2();
t.runIt();
}
}