CSE 142
- Write a method named
printAverage
that accepts aScanner
for the console as a parameter and repeatedly prompts the user for numbers. Once any number less than zero is typed, the average of all non-negative numbers typed is displayed. Display the average as a double, and do not round it. If the first number typed is negative, do not print an average.
An example call might look like ...
Scanner console = new Scanner(System.in);
printAverage(console);
And the output might look like ..
Type a number: 7
Type a number: 4
Type a number: 16
Type a number: -4
Average was 9.0
- Write a method named
hasAnOddDigit
that returns whether any digit of an integer is odd. Your method should returntrue
if the number has at least one odd digit and false if none of its digits are odd. 0, 2, 4, 6, and 8 are even digits and 1, 3, 5, 6, 9 are odd digits. You should not useString
to solve this problem. Some example calls are below.
Call | Value Returned |
---|---|
hasAnOddDigit(4822116); |
true |
hasAnOddDigit(2448); |
false |
hasAnOddDigit(-7004); |
true |
- Write a method named
isAllVowels
that returns whether aString
consists entirely of vowels (a, e, i, o, u)—case-insensitively. If every character of theString
is a vowel, your method should returntrue
. If any character of the String is a non-vowel, your method should return false. Your method should return true if passed the empty string, since it does not contain any non-vowel characters.
Below are some sample calls.
Call | Value Returned |
---|---|
isAllVowels("eIEiO"); |
true |
isAllVowels("oink"); |
false |