-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringTask9.java
More file actions
29 lines (19 loc) · 892 Bytes
/
Copy pathStringTask9.java
File metadata and controls
29 lines (19 loc) · 892 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
import java.util.Scanner;
public class StringTask9 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a line of text: ");
String enteredText = scanner.nextLine();
String[] arrayOfWords = enteredText.split(" ");
System.out.println("Words ending with 'ED':");
for (int currentIndex = 0; currentIndex < arrayOfWords.length; currentIndex++) {
String currentWord = arrayOfWords[currentIndex];
if (currentWord.length() >= 2) {
String lastTwoCharacters = currentWord.substring(currentWord.length() - 2);
if (lastTwoCharacters.equalsIgnoreCase("ed")) {
System.out.println(currentWord);
}
}
}
}
}