Find Vowels And Capital Letter in Array Program in Java
import java.util.Scanner;
public class FindVowelAndCapitalInArray
{
public static void main(String[] args)
{
int vowelCount=0, upperCaseCount = 0;
char ar[] = new char[10];
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 10; i++)
{
System.out.print("Enter the number ar[" + i + "]:");
ar[i] = sc.next().charAt(0);
}
System.out.println("-------------------------------");
for (int i = 0; i < 10; i++)
{
switch(ar[i])
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
vowelCount++;
System.out.println(ar[i]);
break;
default:
}
}
System.out.println("Number of vowels are ="+ vowelCount);
System.out.println("-------------------------------");
for (int i = 0; i < 10; i++)
{
if(Character.isUpperCase(ar[i]))
{
upperCaseCount++;
System.out.println(ar[i]);
}
}
System.out.println("Number of upper case are ="+ upperCaseCount);
}
}
Output:
Enter the number ar[0]:a Enter the number ar[1]:s Enter the number ar[2]:D Enter the number ar[3]:Z Enter the number ar[4]:w Enter the number ar[5]:i Enter the number ar[6]:A Enter the number ar[7]:X Enter the number ar[8]:k Enter the number ar[9]:o ------------------------------- a i A o Number of vowels are =4 ------------------------------- D Z A X Number of upper case are =4java tutorials learn java study java