Results 1 to 2 of 2
  1. #1
    essence388 is offline Member
    Join Date
    Dec 2010
    Posts
    1
    Rep Power
    0

    Default Storing Inputs in Two Linked Arrays

    Hello everybody,

    I am working in a small task that allow the user to enter the regions of any country and store them in one array. Also, each time he enters a region, the system will ask him to enter the neighbours of that entered region and store these regions.

    My idea is each time the user enters the region, the system will store it in an arrya and each time he enters a region, the system will ask him to enter the neighbours of that region before he enters the second region and so on, and store these inputs in a second array under a pointer of the related entry in the first array.

    what I did is just the beginning as follow:

    import java.util.Arrays;
    import java.util.Scanner;

    public class Test {
    public static void main(String[] args) {


    Scanner kb = new Scanner(System.in);


    String [] regionArray = new String[5];

    for (int i = 0; i < regionArray.length; i++) {
    System.out.print("Please enter the region: ");
    regionArray[i] = kb.next();
    //kb.nextLine(); // to get and discard the nextline token
    }

    System.out.print("You have entered: ");

    System.out.println(Arrays.toString(regionArray));
    }
    }


    For example, assume we have 4 regions: a, b, c, d, and a has two neighbours: b and d. In this case when the user enters the first region which is (a), he will be asked to enter its neighbours which are b and d, then he will be able to enter the second region which is b and so on.

    the problem now, How can I genereated the second array and make it linked to the first array?

    Please help me

  2. #2
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    you can use a 2 dimensional array. The first dimension will store the region. The 2nd dimension stores the neighbours.

Similar Threads

  1. help w/ storing/scanning numbers in arrays
    By clemsontigers in forum New To Java
    Replies: 15
    Last Post: 11-18-2010, 06:12 AM
  2. Arrays and use of null or empty inputs
    By Desmond in forum New To Java
    Replies: 6
    Last Post: 07-27-2010, 05:54 PM
  3. Arrays and Null inputs
    By Desmond in forum New To Java
    Replies: 4
    Last Post: 07-21-2010, 07:23 AM
  4. Need help storing arrays from a file
    By arson09 in forum New To Java
    Replies: 4
    Last Post: 03-08-2010, 05:11 PM
  5. Storing and managing huge arrays
    By trust in forum Java Software
    Replies: 2
    Last Post: 08-22-2009, 03:47 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
  •