-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
62 lines (55 loc) · 1.21 KB
/
Main.java
File metadata and controls
62 lines (55 loc) · 1.21 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
import java.io.*;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
Main m = new Main();
FileReader x = m.openFile(args[0]);
BufferedReader y = new BufferedReader(x);
String line;
try {
while((line = y.readLine()) != null){
processLine(line);
}
} catch (IOException e) {
System.out.println("Error reading line");
e.printStackTrace();
}
m.closeFile(x);
}
private static void processLine(String line) {
String[] words = line.split(" ");
int wLen = words.length;
int wLenHalf = wLen/2;
//if(wLen%2 == 0){
for(int i = 0; i < wLenHalf; i++){
String temp = words[i];
words[i] = words[wLen-i-1];
words[wLen-i-1] = temp;
}
//}
for(int i = 0; i < wLen; i++){
System.out.print(words[i] + " ");
}
System.out.println();
}
private FileReader openFile(String file) {
FileReader x = null;
try {
x = new FileReader(new File(file));
} catch (FileNotFoundException e) {
System.out.println("Error reading file.");
e.printStackTrace();
}
return x;
}
private void closeFile(FileReader x) {
try {
x.close();
} catch (IOException e) {
System.out.println("Error closing file.");
e.printStackTrace();
}
}
}