Results 1 to 8 of 8
  1. #1
    dbaby7 is offline Member
    Join Date
    Aug 2009
    Posts
    10
    Rep Power
    0

    Default Program please help

    Hi guys
    Im trying to do this question but I've been stuck on it for ages and despite how much I change it it wont work so if somebody could help that would be great. The question is to read in a word from the user and each time display how many times the word has occured like this
    Success
    0 previous occurrences
    breeds
    0 previous occurrences
    success
    1 previous occurrences
    success
    2 previous occurrences

    This is the program I have


    import java.util.*;

    class Question2
    {
    public static void main(String[] args)
    {
    System.out.println("Enter a word:");

    int count = -1;
    ArrayList<Object> words = new ArrayList<Object>();
    while (!Console.endOfFile())
    {

    String readWord = Console.readString();
    words.add(readWord);

    for (int i = 0; i < words.size() ; i++ )
    {

    if (words.get(i) == readWord)
    {
    count++;
    }

    }
    System.out.println(count + " previous occurances.");
    System.out.println("Enter a word:");

    count = -1;
    }

    }
    }



    Any help would be greatly appreciated
    Thanks

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Where does Console come from?
    Why ArrayList<Object> ?
    words.get(i) == readWord will never work properly. Use String.equals()

  3. #3
    dbaby7 is offline Member
    Join Date
    Aug 2009
    Posts
    10
    Rep Power
    0

    Default Thank you!

    Hi
    Thank you so much for your help! Console is a class file I have in my directory to allow user input. Using String.equals() worked perfectly! I didn't think it wasn't working as I wasn't getting any compile errors! Thank you for your help!

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

  5. #5
    karol is offline Member
    Join Date
    Feb 2010
    Posts
    1
    Rep Power
    0

    Default

    how to make a java program that calculate circumference using applet viewer

  6. #6
    bigj is offline Member
    Join Date
    Dec 2009
    Posts
    68
    Rep Power
    0

    Default

    please create new thread for your post ..

  7. #7
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    Quote Originally Posted by karol View Post
    how to make a java program that calculate circumference using applet viewer
    Creating your own thread would attract more attention for your question which increases the probability of answering your question.

  8. #8
    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. Execute A program from a Program!
    By Moncleared in forum Advanced Java
    Replies: 2
    Last Post: 02-22-2009, 04:17 PM
  2. Executing a program within a program
    By gibsonrocker800 in forum New To Java
    Replies: 5
    Last Post: 05-12-2008, 08:24 AM
  3. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  4. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Tags for this Thread

Posting Permissions

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