Check if count of Alphabets and count of Numbers are equal in the given String | Java program to check if the count of alphabets and numbers in a String are equal or not . ; Function to count the number of alphabets ; Counter to store the number of alphabets in the String ; Every character in the String is iterated ; To check if the character is an alphabet or not ; Function to count the number of numbers ; Counter to store the number of alphabets in the String ; Every character in the String is iterated ; To check if the character is a digit or not ; Function to check if the count of alphabets is equal to the count of numbers or not ; Driver code
class GFG { static int countOfLetters ( String str ) { int letter = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( ( str . charAt ( i ) >= ' A ' && str . charAt ( i ) <= ' Z ' ) || ( str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) ) letter ++ ; } return letter ; } static int countOfNumbers ( String str ) { int number = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) >= '0' && str . charAt ( i ) <= '9' ) number ++ ; } return number ; } static void check ( String str ) { if ( countOfLetters ( str ) == countOfNumbers ( str ) ) System . out . print ( "YesNEW_LINE"); else System . out . print ( "NoNEW_LINE"); } public static void main ( String [ ] args ) { String str = " GeeKs01324" ; check ( str ) ; } }