Professional Documents
Culture Documents
Method Problems Handout
Method Problems Handout
1. Write a value-returning method, isVowel, that returns the value true if a given
character is a vowel, and otherwise returns false.
public static boolean isVowel ( char letter) {
char x;
String str = String.valueOf(letter);
// change the letter to uppercase
x = Character.toUpperCase(letter);
switch (x) {
case 'A':
case 'E':
case 'I':
case 'O':
case 'U': return true;
default: return false;
}
} // end isVowel
Alternately in the method you can use an if statement instead of the case
public static boolean isVowel ( char letter) {
char x;
String str = String.valueOf(letter);
// change the letter to uppercase
x = Character.toUpperCase(letter);
if ((letter == A) || ( letter == E) || (letter == I) || (letter == O) || (letter == U))
return true;
else return false;
} // end isVowel
2. Write a program that prompts the user to input a sequence of characters (as
a string) and outputs the number of vowels. (Hint: Your program should use
the method in the previous problem, use a loop, and methods from class
STring)
} // end of two
}// end of class mystery
a. Write the definition of method one so that it returns the sum of x and
y if x is greater than y; other wise it should return x minus 2 times y.