SHARE
TWEET

Untitled

advictoriam Jan 20th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Words
  2. {
  3.    /**
  4.       Returns the nth short word (length <= 3) in an array.
  5.       @param words an array of strings
  6.       @param n an integer > 0
  7.       @return the nth short word in words, or the empty string if there is
  8.       no such word
  9.    */
  10.    public String nthShortWord(String[] words, int n)
  11.    {
  12.       int count = 1;
  13.       for(String a : words)
  14.       {
  15.          if(a.length() <= 3)
  16.          {
  17.             if(count == n){return a;}
  18.             else{count++;}
  19.          }
  20.       }
  21.       return "";
  22.    }
  23. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top