Write a program that calls a method that takes a character array as a parameter (you can initialize an array in the main method) and returns the number of vowels in the array. Partial program is given below.
![1. Write a program that calls a method that takes a character array as a
parameter (you can initialize an array in the main method) and returns the
number of vowels in the array. Partial program is given below.
public class CountVowels{
public static void main(String[] args){
char[] arr=
System.out.print("There are "+vowels(arr)+" vowels in the array");](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F480f989f-2af6-48a5-ab4d-ef9ac310c5f5%2Fce5e4aa1-46e9-42a6-92f9-a2cf315502f0%2Fxrb2jcw_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Program code:
//define class CountVowels
public class CountVowels
{
//define a method to count the vowels
static int vowels(char arr[])
{
//declare the variables
int count = 0;
char ch;
//iterate a for loop
for (int i = 0; i < arr.length; i++)
{
//get the first charecter to ch
ch = arr[i];
//check if ch is a vowel
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||
ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
//increment the count by 1
count++;
}
//return the value of count
return count;
}
//define main function
public static void main(String[] args)
{
//charecter array
char[] arr={'H','e','l','l','o'};
//print the number of vowels
System.out.print("There are "+vowels(arr)+" vowels in the array");
}
}
Program code #1:
Step by step
Solved in 3 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)