Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. Test Result
  2. String[] words = {"caravan", "car", "van", "bike", "scooter", "vehicle", "bicycle"};
  3.  
  4. findChar('v', words); Words containing the letter v : caravan van vehicle
  5. findChar('i', words); Words containing the letter i : bike vehicle bicycle
  6.  
  7. public static void findChar(Char character, String word) {
  8. for(String word:words) {
  9. // Check if it contains the character
  10. if (word.contains(Character.toString(character))) {
  11. wordsContainingCharacter.add(word);
  12. }
  13.  
  14. if(.....size() > 0) {
  15. System.out.println("Words containing the letter " + character + " : " + ....);
  16. } else {
  17. System.out.println("Character is not in any word");
  18. }
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement