-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
51 lines (43 loc) · 1021 Bytes
/
Main.java
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
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Main fb = new Main();
Scanner x = fb.openFile(args[0]);
while(x.hasNext()){
int f = Integer.parseInt(fb.readLine(x));
int b = Integer.parseInt(fb.readLine(x));
int n = Integer.parseInt(fb.readLine(x));
//System.out.print("f: " + f + " b: " + b + " n: " + n + "\n");
for(int i=1; i<=n; i++){
if(i%f==0 && i%b==0){
System.out.print("FB ");
}
else if(i%f==0){
System.out.print("F ");
}
else if(i%b==0){
System.out.print("B ");
}else System.out.print(i + " ");
}
System.out.println();
}
fb.closeFile(x);
}
private Scanner openFile(String file) {
Scanner x = null;
try {
x = new Scanner(new File(file));
} catch(Exception e) {
System.out.println("Error reading file.");
}
return x;
}
private String readLine(Scanner x) {
String line = x.next();
return line;
}
private void closeFile(Scanner x) {
x.close();
}
}