package countvowels; public class VowelCounter { /** * Calculates the number of vowels in some given text. * Both upper case and lower case vowels count towards the total. * @param text The text which to be searched. * @return The number of vowels in the given text. */ public int numberVowels (String text) { for (int i=0; i<text.length;i++){ if (text=='a' ||text=='e' |text=='i'|text=='o' ||text=='u' || text== 'A' || text=='E' || return i;} } } Count vowels Implement the function public int numberVowels (String text) in the manner described by the comments. Hint: You may find it helpful to use the charAt(index) function.
Added by Concepci-N W.
Close
Step 1
The code is defining a package called "countvowels". Show more…
Show all steps
Your feedback will help us improve your experience
Shaik Dadasaheb and 52 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Write a short Java method that counts the number of vowels in a given character string.
Write a method named tally that takes a String and returns an array of 5 integers containing the frequencies of the 5 vowels (a, e, i, o, u) in the input string. Uppercase and lowercase vowels are counted in the same way. Example: tally("HEY! Apples and bananas!") will return: {5, 2, 0, 0, 0}
Willis J.
Program Requirements: Write a Java program that will 1. Ask the user to type in a sentence, using a JOptionPane.showInputDialog(). 2. The program will examine each letter in the string and count how many times the upper-case letter 'E' appears, and how many times the lower-case letter 'e' appears. The key here is to use the charAt method in class String. 3. Using a JOptionPane.showMessageDialog(), tell the user how many upper and lower case e's were in the string. 4. Repeat this process until the user types the word "Stop". (Check out the method equalsIgnoreCase in class String to cover all upper/lower case possibilities of the word "STOP".
Akash M.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD