Source Code:
public class P12 {
public static void main(String[] args) {
String s = “Aa1!”;
int l=0, sp=0, n=0, o=0;
for(int i=0; i<s.length(); i++) {
char c = s.charAt(i);
if(Character.isLetter(c)) l++;
else if(Character.isDigit(c)) n++;
else if(Character.isWhitespace(c)) sp++;
else o++;
}
System.out.println(l + " " + n + " " + sp + " " + o);
}
}
Output:
