Define a class to declare a character array of size 20. Accept the characters into the array and perform the following;
(i) Count and display the occurrence of the character 'A'
(ii) Count and display the occurrence of other characters other than 'A'.
Answers
Answer:
THE ANSWER TO YOUR PROGRAM IS GIVEN BELOW.
Explanation:
import java.util.*;
class Counts
{
public static void main()
{
Scanner sc = new Scanner(System.in);
char a[] = new char[10];
int count = 0, count_V = 0;
for(int i = 0;i<10;i++)
{
System.out.println("ENTER A characters");
a[i]=sc.next().charAt(0);
}
for(int i = 0;i<10;i++)
{
if(Character.isUpperCase(a[i]))
count++;
if(a[i]=='a' || a[i]=='e')
count_V ++;
}
System.out.println(count);
System.out.println(count_V);
}
}
Answer:
import java.util.*;
class Counts
{
public static void main()
{
Scanner sc = new Scanner(System.in);
char a[] = new char[10];
int count = 0, count_V = 0;
for(int i = 0;i<10;i++)
{
System.out.println("ENTER A characters");
a[i]=sc.next().charAt(0);
}
for(int i = 0;i<10;i++)
{
if(Character.isUpperCase(a[i]))
count++;
if(a[i]=='a' || a[i]=='e')
count_V ++;
}
System.out.println(count);
System.out.println(count_V);
}
}