
Hi, Can you help me with this problem? Run a program that check if the input string contains equal number of A's and B's.
Hoping for your answer.Thank you.

Here is an example that check if the input string contains equal number of A's and B's.
class StringEx
{
public static void main(String[] args)
{
String st="ABRA KA DABRA";
int countA=0,countB=0;
for(int i=0;i<st.length();i++){
char ch=st.charAt(i);
if(ch=='A'){
countA++;
}
if(ch=='B'){
countB++;
}
}
if(countA==countB){
System.out.println("No of A's and B's are equal in string");
}
else{
System.out.println("No of A's and B's are not equal in string");
}
}
}

thank you so much for quick response.very big help
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.