-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShared.java
56 lines (47 loc) · 1.66 KB
/
Shared.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
52
53
54
55
56
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Shared {
static String[] readFile(String fileName) throws IOException {
// list that holds strings of a file
List<String> listOfStrings
= new ArrayList<String>();
// load data from file
BufferedReader bf = new BufferedReader(
new FileReader(fileName));
// read entire line as string
String line = bf.readLine();
// checking for end of file
while (line != null) {
listOfStrings.add(line);
line = bf.readLine();
}
// closing bufferreader object
bf.close();
// storing the data in arraylist to array
return listOfStrings.toArray(new String[0]);
}
static void checkResult(int checkVal, int correctVal) {
if (checkVal == correctVal) {
System.out.println("Correct!");
} else {
System.out.println("***** Incorrect solution. Should be " + correctVal + " *****");
}
}
static void checkResult(long checkVal, long correctVal) {
if (checkVal == correctVal) {
System.out.println("Correct!");
} else {
System.out.println("***** Incorrect solution. Should be " + correctVal + " *****");
}
}
static void checkResult(String checkVal, String correctVal) {
if (checkVal.equals(correctVal)) {
System.out.println("Correct!");
} else {
System.out.println("***** Incorrect solution. Should be " + correctVal + " *****");
}
}
}