954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

I need help outputting the number of upper, lowercase letters digits and puctuation

I have to write code that outputs the number of upper, lowercase digits and punctuation in a string but am having trouble with the asciival command.this is what I have so far but I recieve an error message about the use of my asciival command.an

InputBox input;
input= new InputBox();
input.setPrompt("enter an binary number");
String stringa;
int length;
length=0;
stringa= input.readString();
System.out.print("The total number of Charectures Is:");
System.out.print(stringa.length());
char letter;
int upper;
upper=0;
int increment;
increment=0;
letter=stringa.charAt(increment);
if (asciival(letter)>=65&&asciival(letter)<=90)
upper++;
increment++;

asciival();

dmkrivec
Newbie Poster
1 post since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

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
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You