Results 1 to 6 of 6
- 11-05-2009, 08:22 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 5
- Rep Power
- 0
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.
- 11-05-2009, 11:29 PM #2
Member
- Join Date
- Mar 2009
- Posts
- 81
- Rep Power
- 0
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.
- 11-06-2009, 02:55 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 11-06-2009, 05:40 PM #4
Member
- Join Date
- Oct 2009
- Posts
- 5
- Rep Power
- 0
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
- 11-06-2009, 08:54 PM #5
Member
- Join Date
- Feb 2009
- Posts
- 92
- Rep Power
- 0
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.
- 11-07-2009, 03:33 PM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Did you run and test your code? If so what happen, did you get the expected result or any error?
Similar Threads
-
Starting the console on Mac
By ScottVal in forum New To JavaReplies: 4Last Post: 03-19-2009, 07:24 AM -
starting problem
By anithananduri in forum New To JavaReplies: 1Last Post: 03-17-2009, 01:27 PM -
Need help starting program
By mk3823 in forum New To JavaReplies: 8Last Post: 11-02-2008, 01:41 AM -
Indexing starting with 1
By ravian in forum New To JavaReplies: 4Last Post: 01-04-2008, 12:03 PM -
just starting
By specbailey in forum New To JavaReplies: 23Last Post: 08-13-2007, 11:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks