Question

this is a java course.

the topic is a recursive topic.

Please, very importantly write the testing program in another file. A file for the program and another file for testing the program.

Thanks in advance

Write a recursive method, vowels, that returns the number of vowels in a string. Also, write a program to test your method. 3

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class VowelCountRec {
    static int vowels(String s){
        if(s==null || s.length()==0){
            return 0;
        }
        else{
            char ch = s.charAt(0);
            if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'){
                return 1+vowels(s.substring(1));
            }
            else{
                return vowels(s.substring(1));
            }
        }
    }

    public static void main(String[] args) {
        System.out.println(vowels("qwertyuiq"));
    }
}
Add a comment
Know the answer?
Add Answer to:
this is a java course. the topic is a recursive topic. Please, very importantly write the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem Statement Write a recursive method, vowels, that returns the number of vowels in a string....

    Problem Statement Write a recursive method, vowels, that returns the number of vowels in a string. Also, write a program to test your method in JAVA

  • MUST BE IN JAVA AND USE RECURSION Write a recursive method that returns the number of...

    MUST BE IN JAVA AND USE RECURSION Write a recursive method that returns the number of all occurrences of a given word in all the files under a directory. Write a test program. Use the following header: public static long findInFile(File file, String word)

  • note: the language should be java on netbeans. please solve the question complete. Objective: The students...

    note: the language should be java on netbeans. please solve the question complete. Objective: The students will learn how to work with recursion and improve their problem solving skills. Problem 1: Create an interactive Java Application that has a method to calculate the value of e x = 1 + (x / 1!) + (x2 / 2!) + (x3 / 3!) + … + (xn / n!) Where n and x are supplied by the user. Your must call 2...

  • Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters...

    Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 5×6=6+6+6+6+6 2. Recursive findings Write a recursive boolean method named reFinding. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in...

  • Please use Java. Write a non-recursive method that uses a stack to check whether its string...

    Please use Java. Write a non-recursive method that uses a stack to check whether its string parameter is a palindrome. Write a program to test and demo your method. Fibonacci Numbers Write a method that uses a stack to determine the desired Fibonacci number. Write a program to test and demo your method. Balancing Grouping Symbols Write a method that takes a string parameter and determines whether the string contains matching grouping symbols. Grouping symbols are parenthesis ( ), curly...

  • Java Program Write a recursive method that takes a string and return a string where every...

    Java Program Write a recursive method that takes a string and return a string where every character appears twice. Output must match exactly as below: only two LL's since there is already two of the character For example, if the string is “HELLO”, it will return “HHEELLOO”. Write a program to test it. must be recursive!!!

  • Please write in java Write a main program that runs the following two recursive methods demonstrating...

    Please write in java Write a main program that runs the following two recursive methods demonstrating that they work. #1) Write a recursive method writeSquares that accepts an integer n and prints the first n squares with the odd squares in decending order, followed by the even squares in acending order. For example • writeSquares(8): prints . 49 25 9 1 4 16 36 64 • writeSquares(11); prints 121 81 49 25 9 1 2 16 36 64 100 •...

  • JAVA PLEASE 4. Write a recursive program that converts a Hex base value to its decimal...

    JAVA PLEASE 4. Write a recursive program that converts a Hex base value to its decimal equivalent. This program must validate the ueser’s input. You program must have the main method, inputValidate method and hexToDecimal method. Must implement the last method recursively. Here is a sample output. Enter a valid hex number: 10 Your number in decimal is: 16 Do you have another number: yes Enter a valid hex number: 123 Your number in decimal is: 291 Do you have...

  • In Java, write a program that prompts the user to input a sequence of characters and...

    In Java, write a program that prompts the user to input a sequence of characters and outputs the number of vowels. You will need to write a method to return a value called isAVowel which will return true if a given character is a vowel and returns false if the character is not a vowel. A second method, called isAConstant, should return true if a given character is a constant and return false if the character is not a constant....

  • This is Python coding question, and topic is recursive. Can anyone help me figuring this out?...

    This is Python coding question, and topic is recursive. Can anyone help me figuring this out? (Only recursive function is allowed.) Thanks. Write a function called Fibonacci(n) that takes as a parameter an integer n and returns the nth Fibonacci number. The first two Fibonacci numbers are 1 and every subsequent one is the sum of the previous two: 1, 1, 2, 3, 5, 8, 13, .... Write a recursive function to count the number of uppercase letters in a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT