Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Question: counting

  1. #1
    Junior Member
    Join Date
    Jun 2010
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Question: counting

    Is there a way to write a code that counts every letter, space, characters with the exception of 0-9 and with an exception of not stating what every characters, space, and letter is?

    i.e. If I wanted to count 20482.2140108ab and wanted to return with

    0 3
    1 2
    2 3
    3 0
    4 2
    5 0
    6 0
    7 0
    8 2
    9 0
    other symbols 3

    ?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Question: counting

    Is there a way to write a code that counts
    The answer is yes.
    Do you have more questions on this?

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Question: counting

    Yes, have an array that would denote how many of each item you've found. Since you are only classifying numbers [0-9] and all others as it's own category, you'd have 11 categories.

    Then, you can iterate through each character in the string and determine which category to increase the count for (either using if/else statements or by taking advantage of the underlying unicode representation)

Similar Threads

  1. Program help with counting even and odd integers in input value.
    By fueledbyrick in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 6th, 2010, 07:02 PM
  2. java - soot issue...counting the jimple line numbers??
    By volatile in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 26th, 2010, 12:49 PM
  3. counting words of a text file
    By maybach230 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: May 6th, 2010, 03:40 PM
  4. Counting Vowels and Prepositions in a text file
    By maybach230 in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 27th, 2010, 07:36 PM