-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio.java
More file actions
86 lines (80 loc) · 2.7 KB
/
Copy pathio.java
File metadata and controls
86 lines (80 loc) · 2.7 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.io.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;
public class io{
public static void main(String[] args) {
System.out.println(getSmallestEven("numbers1.txt"));
}
private static int getSmallestEven(String string) {
Scanner fileInput = null;
String[] list = null;
try {
fileInput = new Scanner(new File(string));
while (fileInput.hasNextLine()) {
list = fileInput.nextLine().split(",");
}
} catch (Exception e) {
System.out.printf("ERROR: The file \'%s\' does not exist.", string);
return 999;
} finally {
if (fileInput != null) {
fileInput.close();
}
}
int current = 0;
int min = 999;
for (int i = 0; i < list.length; i++) {
current = Integer.parseInt(list[i]);
if (current % 2 == 0) {
min = Math.min(min, current);
}
}
return min;
}
private static void encryptText(String string) {
Scanner fileInput = null;
try {
fileInput = new Scanner(new File(string));
while (fileInput.hasNext()){
StringBuilder word = new StringBuilder(fileInput.next());
for (int i = 0; i < word.length() ; i++) {
if (Character.isLowerCase(word.charAt(i))) {
word.setCharAt(i, Character.toLowerCase((char) (word.charAt(i) + 1)));
}
}
System.out.print(word + " ");
}
} catch (Exception e) {
System.out.println("ERROR: The file 'error.txt' does not exist.");
} finally {
if (fileInput != null) {
fileInput.close();
}
}
}
private static ArrayList<String> getWordsList(String string, int i) {
ArrayList<String> out = new ArrayList<String>();
Scanner input = null;
try {
input = new Scanner(new File(string));
while (input.hasNext()) {
String word = input.next().toLowerCase();
if (word.length() == i){
if (out.contains(word) == false) {
out.add(word);
}
}
}
} catch (IOException e) {
System.out.printf("ERROR: The file \'%s\' does not exist.\n", string);
// TODO: handle exception
} finally {
if (input != null){
input.close();
}
}
out.sort(Comparator.naturalOrder());
return out;
}
}