Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Test Result
- String[] words = {"caravan", "car", "van", "bike", "scooter", "vehicle", "bicycle"};
- findChar('v', words); Words containing the letter v : caravan van vehicle
- findChar('i', words); Words containing the letter i : bike vehicle bicycle
- public static void findChar(Char character, String word) {
- for(String word:words) {
- // Check if it contains the character
- if (word.contains(Character.toString(character))) {
- wordsContainingCharacter.add(word);
- }
- if(.....size() > 0) {
- System.out.println("Words containing the letter " + character + " : " + ....);
- } else {
- System.out.println("Character is not in any word");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement