Unformatted text preview:

Sample methods to write 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 3 Consider the following program outline public class Mystery public static void main String args int num double dec some statements go here end of main public static int one int x int y end of one public static double two int x double a int first double z 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 b write the definition of method two as follows i read a number and store it in z ii update the value of z by adding the value of a to it iii assign the variable first the value returned by method one with the parameters 6 8 iv update the value of first by adding the value of x to its previous value v if the value of z is more than twice the value of first return z otherwise return 2 times first minus z 4 Write a method reverseDigit that takes an integer as a parameter and returns the number with its digits reversed For example the value of reverseDigit 123 is 321 Also write a main program to test your program


View Full Document

WVU CS 110 - Sample Methods to Write

Loading Unlocking...
Login

Join to view Sample Methods to Write and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Sample Methods to Write and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?