-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordSeperator.java
More file actions
46 lines (34 loc) · 1.09 KB
/
WordSeperator.java
File metadata and controls
46 lines (34 loc) · 1.09 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
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class WordSeperator {
public static void main(String[] args) throws FileNotFoundException {
File dict = new File("dictionary.txt");
Scanner ds = new Scanner(dict);
Scanner kb = new Scanner(System.in);
String root, checkMe = "";
ArrayList<String> words = new ArrayList<String>();
while(ds.hasNext()) {
words.add(ds.nextLine());
}
System.out.println("Enter the phrase to seperate the words from: ");
root = kb.nextLine();
while(root.length() > 0) {
checkMe = "";
for(int i = 0; i < root.length(); i++) {
checkMe = checkMe + root.charAt(i);
for(int j = 0; j < words.size(); j++) {
if(checkMe.contentEquals(words.get(j))) {
System.out.println(checkMe);
root = removeElement(checkMe, root);
}
}
}
}
}
private static String removeElement(String checkMe, String root) {
int chomp = checkMe.length();
return root.substring(chomp, root.length());
}
}