
i have to print the total number of char 'A' in all string entered..
example: please enter your string: selangor melaka kedah sabah sarawak terengganu
the output must be count the total number of char 'A'...

import java.util.*;
class CountCharacter
{
public static void main(String[] args)
{
int count=0;
Scanner input=new Scanner(System.in);
System.out.print("Enter string: ");
String str=input.nextLine();
char arr[]=str.toLowerCase().toCharArray();
for(int i=0;i<arr.length;i++){
if(arr[i]=='A'||arr[i]=='a'){
count++;
}
}
System.out.println("Character occurs "+count+" times");
}
}

import java.util.*;
class CountCharacter
{
public static void main(String[] args)
{
int count=0;
Scanner input=new Scanner(System.in);
System.out.print("Enter string: ");
String str=input.nextLine();
char arr[]=str.toLowerCase().toCharArray();
for(int i=0;i<arr.length;i++){
if(arr[i]=='A'){
count++;
}
}
System.out.println("Character occurs "+count+" times");
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.