I am trying to print the output of a String to find the count of uppercase and lowercase in it.
E.g. if string = "AaaBBbCc", I need the output as : "A1a2B2b1C1c1".
I.E. count of uppercase 'A' then count of lowercase 'a', appending with the characters.
Below is the code snippet till where I have done. Can any one suggest how it goes. I know code is not up-to the mark :(
public static void main(String[] args) {
String str = "AaaBBbCc";
int upperCount=0;
int lowerCount=0;
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
if(ch>='A' && ch<='Z'){
upperCount++;
System.out.println("Uppercase letter is : "+ch+upperCount);
}
if(ch>='a' && ch<='z'){
lowerCount++;
System.out.println("Lower case letter is : "+ch+lowerCount);
}
}
System.out.println("upper count is :"+upperCount+" & lower count is: "+lowerCount);
}