Advertisement
droidus

Untitled

Sep 15th, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. public class GetBigWords {
  2.  
  3.     /**
  4.      * @param args the command line arguments
  5.      */
  6.     public static void main(String[] args) {
  7.         String[] array = new String [50];
  8.     String sentence = "There are 87,000,000 people in Canada";
  9.     int sentenceLength = sentence.length();
  10.     int k=0; // counter for the array, "array"
  11.     int h=0; // counter for first time inserting into array -- may not need!!
  12.    
  13.     // STEP ONE
  14.     for (int i = 0; i<sentenceLength; i++) // set up the array with the words
  15.     {
  16.         if (array[k] == null) // make sure to empty the slot of the array element first!!
  17.         {
  18.             array[k] = "";
  19.         }
  20.         if(sentence.charAt(i) != (' ')) // as long as we haven't reached a space,
  21.         // update the string in the array with the new string
  22.         {
  23.                     array[k] = array[k] + sentence.charAt(i);
  24.         }
  25.         else
  26.         {
  27.                     k += 1; // go to the next spot to get the next word
  28.         }
  29.     }
  30.        
  31.         // Step 2
  32.         int l = 0;
  33.         for (int i = 0; i<array.length; i++)
  34.         {
  35.             int wordLength = array[i].length();
  36.             boolean numberCheck = false;
  37.            
  38.             for (k = 0; k<array.length; k++) // check if the string is a number
  39.                 {
  40.                 char digit = array[i].charAt(0);
  41.                     if(isDigit(digit))
  42.                     {
  43.                         numberCheck = true;
  44.                     }
  45.                 }
  46.            
  47.             if (wordLength > 5 && numberCheck == false)
  48.             {
  49.                 System.out.println(array[i]);
  50.             }
  51.         }
  52.        
  53.  
  54.        
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement