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 5 of 5

Thread: NEED HELP! ROOKIE JAVA USER

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default NEED HELP! ROOKIE JAVA USER

    Hello,

    I just started to work with java a few months ago. I am trying to write a program that reads a text file, counts the number of words, and the number of times each word is repeated. Can anyone post the code for a program that does this? Help would be greatly appreciated.


  2. #2
    Member Kewish's Avatar
    Join Date
    Apr 2013
    Location
    Australia
    Posts
    116
    Thanks
    10
    Thanked 17 Times in 14 Posts

    Default Re: NEED HELP! ROOKIE JAVA USER

    Hi Alex8 and welcome to JPF.

    No one will write the code for you. What will happen if you post your code along with the problem you're having (include input, output and any exceptions/errors), you will get some helpful advice on how to proceed.

    What you've written above already has three problems for you to work on.

    Problem 1 - reads a text file
    Problem 2 - counts the number of words
    Problem 3 - and the number of times each word is repeated

    Work on each problem as if they're the only problem. Join them together and you'll be well on your way. After a couple of months of Java you should be able to do at least the last two if not the File IO as well.

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: NEED HELP! ROOKIE JAVA USER

    Quote Originally Posted by alex8 View Post
    Can anyone post the code for a program that does this?
    Sure!
    class Cheater {
        public static void main(String[] args) {
            System.out.println("Do your own work!");
        }
    }
    Improving the world one idiot at a time!

  4. #4
    Junior Member
    Join Date
    Nov 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEED HELP! ROOKIE JAVA USER

    this is my attempt to open a file so far...I am completely lost


    import

    java.io.InputStreamReader;

    import

    java.io.BufferedReader;

    import

    java.util.ArrayList;

    import

    java.util.Scanner;

    public

    class WordCount2 {

    public static void main(String[] args) {

    // TODO Auto-generated method stub

    //CountWords("Z:\\javamonkey.txt");

    BufferedReader bufferedreader =

    new BufferedReader(new InputStreamReader(System.in));

    ArrayList<String> prepwords = CountWords(

    "Z:\\javamonkey.txt");

    System.

    out.println(prepwords.size));

    }

    public static ArrayList<String> CountWords (String file){

    Scanner in =

    new Scanner(file).useDelimiter(" ");

    ArrayList<String> sWordList =

    new ArrayList<String>();

    while(in.hasNext())

    prepwords.add(in.next());

    return prepwords;

    }

  5. #5
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: NEED HELP! ROOKIE JAVA USER

    Quote Originally Posted by alex8 View Post
    I am completely lost
    How are we supposed to help? The more details you provide and the more specific question you ask (yes you need to ask a question) the better response you will get.

    Also posting code inside code tags and include any error messages you get helps.
    Improving the world one idiot at a time!

Similar Threads

  1. Big Rookie Question - New to Java, small problem Help appreciated!
    By Knighter in forum What's Wrong With My Code?
    Replies: 8
    Last Post: September 24th, 2013, 01:55 AM
  2. Rookie Question! Help Appreciated
    By Knighter in forum Java Theory & Questions
    Replies: 23
    Last Post: September 23rd, 2013, 09:13 PM
  3. Rookie here, need help with sum of digits program
    By wkellogg10 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 12th, 2013, 07:25 PM
  4. Hello every user.. Please help in me my java assignment !!!
    By commandor in forum Algorithms & Recursion
    Replies: 1
    Last Post: March 11th, 2012, 10:24 AM
  5. Trying to get Java to ask the user for a number
    By SunsetSkies in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 26th, 2012, 06:18 PM