Something like this?
public class Test
{
public static void main (String[] args)
{
String str = "HellO THIS is @#@%@ a M*#ED string";
int length = str.length();
int upperCount = 0;
int lowerCount = 0;
int punctCount = 0;
int digitCount = 0;
int whiteSpaceCount = 0;
char ch = ' ';
for(int i = 0; i < length; ++i)
{
ch = str.charAt(i);
if(Character.isUpperCase(ch) == true)
++upperCount;
else if(Character.isLowerCase(ch) == true)
++lowerCount;
else if(Character.isDigit(ch) == true)
++digitCount;
else if(Character.isWhitespace(ch) == true)
++whiteSpaceCount;
else
++punctCount;
}
System.out.println("\nUppercase: " + upperCount +
"\nLowercase: " + lowerCount +
"\nDigits: " + digitCount +
"\nWhitespaces: " + whiteSpaceCount +
"\nPunctuation: " + punctCount);
}
} Uppercase: 9 Lowercase: 12 Digits: 0 Whitespaces: 6 Punctuation: 7
~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734