Results 1 to 6 of 6
  1. #1
    SF163 is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default Help with starting program please

    I am currently having extreme difficulty starting to write program for my java class. I've been struggling with this first java class and if anyone could shed some light and help me I would aprreciate it very much. I have to create a program where any number of input lines is put in by the keyboard and using arrays i have to count the frequency of each letter, put it to lowercase, and print out the number of times each letter occurs. The two classes im using is the driver class LetterFreq and the class Letters. I don't know where to start and am wondering if anyone can help. I don't really have any code besides declaring the classes and main so any help or starting point would be appreciated.

  2. #2
    bubbless is offline Member
    Join Date
    Mar 2009
    Posts
    81
    Rep Power
    0

    Default

    You can make two arrays.
    One with 26 strings/chars (a-z) and one with 26 int's. (letter counts)

    When the user inputs a letter, add one to the int array.
    In the end, display the int for each letter.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    First start from how the user input handle. Have to find out what type of character is entered by the user, letter or a character. If it's a character then you have to convert then into a lowercase. It's really easy task to do. Then as bubbless say you can do a simple comparison.

    Take a start and show your effort here. Then we can comment on each step.

  4. #4
    SF163 is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default

    I've got thhis for the driver class so far but I don't know if its reading in the way I want it to.
    Java Code:
    import java.util.*;
    
    public class LetterFreq{
      public static void main(String[] args){
        String[] lines = new String[50];
        Scanner scan = new Scanner(System.in);
        int pos = 0;
        String t = " ";
        while(t.length() > 0){
          t = scan.nextLine();
          lines[pos] = t;
          pos++;
          }
        t= t.toLowerCase();
      }
    }
    Last edited by Eranga; 11-07-2009 at 03:32 PM. Reason: added code tags

  5. #5
    rdtindsm is offline Member
    Join Date
    Feb 2009
    Posts
    92
    Rep Power
    0

    Default

    Poor man's debugger and a really useful tool is the println statement.

    System.out.println(lines[index_value]);

    will verify that you are reading and storing data.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Starting the console on Mac
    By ScottVal in forum New To Java
    Replies: 4
    Last Post: 03-19-2009, 07:24 AM
  2. starting problem
    By anithananduri in forum New To Java
    Replies: 1
    Last Post: 03-17-2009, 01:27 PM
  3. Need help starting program
    By mk3823 in forum New To Java
    Replies: 8
    Last Post: 11-02-2008, 01:41 AM
  4. Indexing starting with 1
    By ravian in forum New To Java
    Replies: 4
    Last Post: 01-04-2008, 12:03 PM
  5. just starting
    By specbailey in forum New To Java
    Replies: 23
    Last Post: 08-13-2007, 11:25 PM

Posting Permissions

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