intro/CountBigWords

From ggc

Jump to: navigation, search

01 package intro;
02 //start auto-imports
03 import java.util.*;
04 //end auto-imports
05 
06 
07 /**
08  * All about my application.
09  @author My Name Here
10  */
11 public class CountBigWords
12 {
13   /**determines the number of big words in a collection of
14    * words.  A big word is considered to be a word with 8
15    * or more letters in it.
16    * Examples:
17    <"Happy", "Sad", "Super-smart"> -> 1
18    <"Happy-sad", "Super-smart"> -> 2
19    <"cat", "dog", "bunny"> -> 0
20    @param words the collection of words to look through
21    * @returns the number of big words in the collection words
22    */
23   public int getBigWordCount(ArrayList<String> words)
24   {
25     int count=0;
26     for(String single: words)
27       //for(int i=0; i<words.size(); i++)
28       //{
29       //   String single=words.get(i);
30     {
31       if(single.length()>=8)
32       {
33         count++;
34       }
35     }
36     return count;
37   }
38 
39   public static void main(String[] args)
40   {
41     ArrayList<String> words=new ArrayList<String>();
42     words.add("Happy");
43     words.add("Sad");
44     words.add("Bunnty");
45     CountBigWords counter=new CountBigWords();
46     int count=counter.getBigWordCount(words);
47     System.out.println("The number of big words is "+count);
48   }
49 }


Download/View intro/CountBigWords.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter