C:\Users\notebook\Documents\NetBeansProjects\CS2\src\review\LongerWords.java
 1 /*
 2  * Program to prompt the user for a punctuation free sentence and then print 
 3  * the words in the sentence that are longer then the average word length of 
 4  * the sentence, one word per line.
 5  */
 6 package review;
 7 
 8 import java.util.ArrayList;
 9 import java.util.Scanner;
10 
11 /**
12  *
13  * @author notebook
14  */
15 public class LongerWords {
16 
17     /**
18      * @param args the command line arguments
19      */
20     public static void main(String[] args) {
21         System.out.print("Sentence?  ");
22         Scanner scanner = new Scanner(System.in);
23         ArrayList<String> words = new ArrayList<>();
24         String sentence = scanner.nextLine();
25         String[] splitedSentence = sentence.split(" ");
26         for (int a = 0; a < splitedSentence.length; a = a + 1) {
27             words.add(splitedSentence[a]);
28         }
29         int sumOfWordLength = 0;
30         for ( int x = 0; x < words.size(); x = x + 1) {
31             String word = words.get(x);
32             int wordLength = word.length();
33             sumOfWordLength = sumOfWordLength + wordLength;
34         }
35         double avgWordLength = sumOfWordLength/words.size();
36         System.out.println("The longer words ...");
37         for ( int x = 0; x < words.size(); x = x + 1) {
38             if (words.get(x).length() > avgWordLength) {
39                 System.out.println(words.get(x));
40             }
41         }
42     }
43 
44 }
45