C:\Users\notebook\Documents\NetBeansProjects\CS2\src\review\NonextremeWords.java |
1
2
3
4
5
6
7
8 package review;
9
10 import java.util.ArrayList;
11 import java.util.Scanner;
12
13
14
15 @author
16
17 public class NonextremeWords {
18
19
20 @param args
21
22 public static void main(String[] args) {
23 System.out.print("Sentence? ");
24 Scanner scanner = new Scanner(System.in);
25 ArrayList<String> words = new ArrayList<>();
26 String sentence = scanner.nextLine();
27 String[] word = sentence.split(" ");
28 for (int a = 0; a < word.length; a = a + 1) {
29 words.add(word[a]);
30 }
31 compareWords(words);
32 for (int x = 0; x < words.size(); x = x + 1) {
33 System.out.println(words.get(x));
34 }
35 }
36
37 private static void compareWords(ArrayList<String> words) {
38 String biggest = "aaaaa";
39 for ( int c = 0; c < words.size(); c = c + 1 ) {
40 if (words.get(c).compareTo(biggest) > 0) {
41 biggest = words.get(c);
42 }
43 }
44 for (int d = 0; d < words.size(); d = d + 1) {
45 if (words.get(d).equalsIgnoreCase(biggest)) {
46 words.remove(d);
47 d = d - 1;
48 }
49 }
50 String smallest = "zzzzz";
51 for ( int c = 0; c < words.size(); c = c + 1 ) {
52 if (words.get(c).compareTo(smallest) < 0) {
53 smallest = words.get(c);
54 }
55 }
56 for (int d = 0; d < words.size(); d = d + 1) {
57 if (words.get(d).equalsIgnoreCase(smallest)) {
58 words.remove(d);
59 d = d - 1;
60 }
61 }
62 }
63
64 }
65