Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Words
- {
- /**
- Returns the nth short word (length <= 3) in an array.
- @param words an array of strings
- @param n an integer > 0
- @return the nth short word in words, or the empty string if there is
- no such word
- */
- public String nthShortWord(String[] words, int n)
- {
- int count = 1;
- for(String a : words)
- {
- if(a.length() <= 3)
- {
- if(count == n){return a;}
- else{count++;}
- }
- }
- return "";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement