forked from sarjus/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWords.java
More file actions
31 lines (31 loc) · 925 Bytes
/
Words.java
File metadata and controls
31 lines (31 loc) · 925 Bytes
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
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class Words {
public static void main(String[] args) throws FileNotFoundException {
ArrayList<String> allWords = new ArrayList<String>();
Scanner input = new Scanner(new File("words.txt"));
while (input.hasNext()) {
String word = input.next();
allWords.add(word);
}
System.out.println("The List: "+allWords);
System.out.println("display in reverse order");
// Display the words in the reverse order
for (int i = allWords.size() -1; i >= 0; i--) {
System.out.print(allWords.get(i)+" ");
}
System.out.print("\n");
// remove all plural words
for (int i = 0; i < allWords.size(); i++) {
String word = allWords.get(i);
if (word.endsWith("s")) {
allWords.remove(i);
i--;
}
}
System.out.println("The List after removal: " + allWords);
input.close();
}
}