-
Notifications
You must be signed in to change notification settings - Fork 0
/
codeFile.java
50 lines (44 loc) · 1.35 KB
/
codeFile.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
import java.io.*;
class A{
public static FileWriter createFile() {
try {
FileWriter myWriter = new FileWriter("codeTestOutput.txt");
return myWriter;
}
catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
return null;
}
public static void writeFile(FileWriter writer, String text){
try{
writer.write(text + "\n");
return;
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
return;
}
public static void closeFile(FileWriter writer){
try{
writer.close();
return;
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
return;
}
public static boolean selectItem ( int [ ] nums , int item ) { for ( int i = 0 ; i < nums. length ; i ++ ) { if ( nums [ i ] == item ) { return true ; } } return false ; }
public static void main(String[] args){
FileWriter writer = createFile();
writeFile(writer, String.valueOf(selectItem(new int[] {1, 2, 3, 4}, 3)));
writeFile(writer, String.valueOf(selectItem(new int[] {1, 2, 3, 4}, 7)));
writeFile(writer, String.valueOf(selectItem(new int[] {1, 2, 3, 4}, 4)));
writeFile(writer, String.valueOf(selectItem(new int[] {1, 2, 3, 4, 4, 4}, 4)));
writeFile(writer, String.valueOf(selectItem(new int[] {1, 2, 3, 4, 4, 4}, 6)));
closeFile(writer);
}
}