// Tyler Rigsby, CSE 142 // Example boolean methods involving testing Strings and chars for vowels public class Vowels { public static void main(String[] args) { System.out.println(isLowercaseVowel('a')); System.out.println(isLowercaseVowel('c')); System.out.println("alphabet: " + hasLowercaseVowel("alphabet")); System.out.println("crwth: " + hasLowercaseVowel("crwth")); System.out.println("hello: " + hasLowercaseVowel("hello")); } // Takes a String as a parameter and returns true if it has a lowercase vowel // or false otherwise public static boolean hasLowercaseVowel(String text) { for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); if (isLowercaseVowel(c)) { // bad boolean zen: isLowercaseVowel(c) == true return true; } } return false; } // Takes a char as a parameter and returns true if it is a vowel, false otherwise public static boolean isLowercaseVowel(char c) { boolean isVowel = c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'; return isVowel; /* bad boolean zen: if (isVowel) { return true; } else { return false; }*/ } }