Results 1 to 2 of 2
  1. #1
    Meta is offline Member
    Join Date
    Mar 2010
    Posts
    78
    Rep Power
    0

    Default 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 :(

  2. #2
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    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

  1. Mostly completed array search program
    By Ryujin89 in forum New To Java
    Replies: 1
    Last Post: 11-04-2009, 03:25 AM
  2. Need help with program: arrays
    By dangerzone9k in forum New To Java
    Replies: 2
    Last Post: 04-02-2009, 05:59 AM
  3. Hash table with linear probing
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-12-2008, 08:43 PM
  4. Help me(Linear Multiobjective programming)
    By vinaytvijayan in forum Advanced Java
    Replies: 2
    Last Post: 01-22-2008, 07:24 AM
  5. problem with recursive binary search program
    By imran_khan in forum New To Java
    Replies: 3
    Last Post: 08-02-2007, 03:08 PM

Posting Permissions

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