Question

In: Computer Science

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

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

(JAVA Code)

Solutions

Expert Solution

import java.util.Scanner;

public class Main {
        
        public static int vowels(String s) {
                
                int count = 0;
                s = s.toLowerCase();
                
                for(char c: s.toCharArray()) {
                        if("aeiou".contains(c + "")) {
                                count++;
                        }
                }
                
                return count;
                
        }

        public static void main(String[] args) {

                Scanner scnr = new Scanner(System.in);

                System.out.println("Enter your sentence: ");
                String s = scnr.nextLine();
                
                System.out.println("number of vowels: " + vowels(s));
                
                scnr.close();

        }

}

Related Solutions

Code in Java Write a recursive method, reverseString, that accepts a String and returns the String...
Code in Java Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write a recursive method, reverseArrayList, that accepts an ArrayList of Strings and returns the ArrayList in reserve order in reserve order of the input ArrayList. Write a main method that asks the user for a series of Strings, until the user enters “Done” and puts them in an ArrayList. Main should make use to reverseArrayList and reverseString to reverse each String in the...
java/netbeans Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write...
java/netbeans Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write a recursive method, reverseArrayList, that accepts an ArrayList of Strings and returns an ArrayList in reserve order of the input ArrayList. Write a main method that asks the user for a series of Strings, until the user enters “Done” and puts them in an ArrayList. Main should make use to reverseArrayList and reverseString to reverse each String in the ArrayList and then reverse the...
Write a recursive method to determine if a String is a palindrome. The program should contain...
Write a recursive method to determine if a String is a palindrome. The program should contain a String array that you can load several test cases to test your palindrome testing method. The program should load your String Array with the test data containing the possible palindromes from a text file. The program should test you application with a text file contained in your project folder After testing your program with your test cases in the text file, you program...
Write a recursive method to determine if a String is a palindrome. The program should contain...
Write a recursive method to determine if a String is a palindrome. The program should contain a String array that you can load several test cases to test your palindrome testing method. The program should load your String Array with the test data containing the possible palindromes from a text file. The program should test you application with a text file contained in your project folder After testing your program with your test cases in the text file, you program...
Write a recursive method using Java that takes a string s as input and returns a...
Write a recursive method using Java that takes a string s as input and returns a list that contains all the anagrams of the string s. An anagram is a word formed by rearranging the letters of a different word. For instance, the word ‘cat’ is an anagram of ‘act’. Notice that the output list cannot contain duplicates.
Write a recursive method to determine if a String is a palindrome. Create a String array...
Write a recursive method to determine if a String is a palindrome. Create a String array with several test cases and test your method. Write a recursive method to determine if a String is a palindrome. Create a String array with several test cases and test your method. In Java
Write a RECURSIVE method that receives a string as a parameter. The method will return true...
Write a RECURSIVE method that receives a string as a parameter. The method will return true if the string received as a parameter is a palindrome and false if it is not. The method must not have any loops! In JAVA
Write a short program that performs the following: - Method city returns the string "Seattle": -...
Write a short program that performs the following: - Method city returns the string "Seattle": - Method named state returns the string "Washington ": - Method named report calls the city methodand calls the state method. and prints their return values, so that the output will appear as : "Seattle Washington "
Write a recursive method repeatNTimes(String s, int n) that accepts a String and an integer as...
Write a recursive method repeatNTimes(String s, int n) that accepts a String and an integer as two parameters and returns a string that is concatenated together n times. (For example, repeatNTimes ("hello", 3) returns "hellohellohello") Write a driver program that calls this method from the Main program. Need code in c#.
Exercise: Recursive List Processing Part 1: Write a recursive method that returns the length (an int)...
Exercise: Recursive List Processing Part 1: Write a recursive method that returns the length (an int) of the longest String in a List of Strings. For each recursive call, remove the first String from the list and return the greater of the length of the String you removed or the result of calling the method on the remainder of the list. The base case should be that the size of the list is 0. Write a driver to verify that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT