Results 1 to 2 of 2
- 03-10-2010, 10:55 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 78
- Rep Power
- 0
Please help me with this program (Linear Search two arrays)
I have been staring at my stupid book for days. The book doesnt detail how to do what i want, and only uses integers, not strings. Basically i have 2 arrays initialized. One array has english words, then the other array has spanish words that are in the same order as their english counterparts. Basically what i have to do is use linear search and let the user enter a word in english or spanish(i guess use methods for them to decide), and then translate the word. Im seriosuly frustrated beyond belief. This is all i have:
public class Lab2
{
public static void main(String [ ] args)
{
String[] EnglishArray = {"cat", "dog", "house", "table", "turtle", "water", "yellow", "zoo"};
String[] SpanishArray = {"gato", "perro", "casa", "mesa", "tortuga", "agua", "amarillo", "zoologico"};
\ive tried so much and deleted like anything ive odne. help :(
- 03-11-2010, 12:49 AM #2
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
This is homework, so I won't give you the answer in code, but I can give you some hints, I suppose.
You're going to start with the word your user entered in a String variable -- let's say it's input. Then you'll use a loop (probably a for loop) to step through the arrays, one word at a time, checking if, for example, EnglishArray[i].equals(input). If you get a match, return the word with the same index from the other array. If you loop through all the words and never find a match, you should return "word not found" or something like that.
If that doesn't help, show us what code you have, and maybe we can point out where you are having trouble.
Similar Threads
-
Mostly completed array search program
By Ryujin89 in forum New To JavaReplies: 1Last Post: 11-04-2009, 03:25 AM -
Need help with program: arrays
By dangerzone9k in forum New To JavaReplies: 2Last Post: 04-02-2009, 05:59 AM -
Hash table with linear probing
By Java Tip in forum java.langReplies: 0Last Post: 04-12-2008, 08:43 PM -
Help me(Linear Multiobjective programming)
By vinaytvijayan in forum Advanced JavaReplies: 2Last Post: 01-22-2008, 07:24 AM -
problem with recursive binary search program
By imran_khan in forum New To JavaReplies: 3Last Post: 08-02-2007, 03:08 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks