Results 1 to 3 of 3

Thread: help

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2003
    Location
    Ontario, Canada
    Posts
    12

    help

    i need a string of sentences to pass to a method along with an array of letters from ?a? to ?z?. The method steps through each string and determines the number of a?s, b?s, c?s, ?, z?s in each line and in the paragraph in total. im new with java so any help is appreciated.
    Phil

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Have you even tried yet?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Addicted Member MethadoneBoy's Avatar
    Join Date
    Oct 2001
    Location
    Preferably somewhere between Keira Knightley and Diane Kruger but I'm not fussy
    Posts
    180
    Use a StringTokenizer object to parse the String and create an array of integers that keeps track of the amount of times each letter occurs.

    eg:

    Code:
    private int[] countArray = new int[26];
    private char[] characters = new char[26];
    
    private int[] parse ( String S ) {
    
          StringTokenizer ST = new StringTokenizer ( S );
    
          while ( ST.hasMoreTokens () ) {
    
                String next = ST.nextToken ();
                char[] c = next.toCharArray ();
    
                for ( int i = 0; i < c.length; i ++ ) {
    
                      System.out.println ( c[i] );
    
                      if ( isInCharacters ( c[i] ) {
    
                            int position = positionOfCharacter ( c[i] );
                            countArray[position] ++;
    
                      }
    
               }
    
          }
    
    }
    The isInCharacters ( char a ) method would sweep through the characters array and check to see if the character you just passed into it is there.

    Hope this helps!
    "'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width