Results 1 to 8 of 8
Thread: Program please help
- 08-12-2009, 04:31 PM #1
Member
- Join Date
- Aug 2009
- Posts
- 10
- Rep Power
- 0
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
- 08-12-2009, 04:44 PM #2
Where does Console come from?
Why ArrayList<Object> ?
words.get(i) == readWord will never work properly. Use String.equals()
- 08-12-2009, 04:49 PM #3
Member
- Join Date
- Aug 2009
- Posts
- 10
- Rep Power
- 0
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!
- 08-14-2009, 04:51 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
If you have solve the problem please mark that from thread tools, as solved.
- 02-08-2010, 07:02 AM #5
Member
- Join Date
- Feb 2010
- Posts
- 1
- Rep Power
- 0
how to make a java program that calculate circumference using applet viewer
- 02-08-2010, 07:05 AM #6
Member
- Join Date
- Dec 2009
- Posts
- 68
- Rep Power
- 0
please create new thread for your post ..
- 02-08-2010, 07:29 AM #7
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
- 02-11-2010, 05:43 PM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Sorry I've to close this thread. If anyone of you want please contact me though PMs regarding this.
Similar Threads
-
Execute A program from a Program!
By Moncleared in forum Advanced JavaReplies: 2Last Post: 02-22-2009, 04:17 PM -
Executing a program within a program
By gibsonrocker800 in forum New To JavaReplies: 5Last Post: 05-12-2008, 08:24 AM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM


LinkBack URL
About LinkBacks


Bookmarks