Define a class to declare a character array of size ten, accept the character into the array and perform the following: Count the number of uppercase letters in the array and print. Count the
Advertisements
Question
Define a class to declare a character array of size ten, accept the character into the array and perform the following:
- Count the number of uppercase letters in the array and print.
- Count the number of vowels in the array and print.
Answer in Brief
Advertisements
Solution
public class CountUpperLower
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int uppercase = 0;
int vowels = 0;
char chh,ch;
System.out.println("Input some characters... ");
char[10] a = sc.next().toCharArray();
for(int i=0;i<a.length;i++)
{
chh=a[i];
System.out.print(a[i]);
if(chh >='A' && chh <='Z')
uppercase++;
ch=Character.toUpperCase(chh);
if (ch='A' || ch-'E' || ch-'I' || ch='O' || ch='U')
vowels++;
}
System.out.println("Count of uppercase letters:" + uppercase);
System.out.println("Count of vowels:"+ vowels);
}
}shaalaa.com
Is there an error in this question or solution?
