Results 1 to 5 of 5
  1. #1
    sims34 is offline Member
    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Default Assign data enter by user to a 2D Array

    I new to Java so bare with me. I've started the program which prompts user to enter random data until the "done". I completed that part, now I have to store the info they typed in to an array and then I have to

    display: As Entered
    for each entry in the array, display the index of the first dimension, the second dimension's value, and the first dimension's value on a single line separated by : (colon).

    display: Bubble Sorted
    using a bubble sort, for each entry in the array, display the original index of the first dimension, the second dimension's value, and the first dimension's value on a single line separated by : (colon) sorted by the second dimension.

    display: Selection Sorted
    using a selection sort, for each entry in the array, display the original index of the first dimension, the second dimension's value, and the first dimension's value on a single line separated by : (colon) sorted by the first dimension.

    And it should look like this:

    User types:
    apple
    Apple
    Zone
    apple
    done

    You display:
    As entered
    0:a:apple
    1:a:Apple
    2:z:Zone
    3:a:apple
    Bubble Sorted
    0:a:apple
    1:a:Apple
    3:a:apple
    2:z:Zone
    Selection Sorted
    1:a:Apple
    0:a:apple
    3:a:apple
    2:z:Zone


    Any help will be greatly appreciated.

  2. #2
    jhuber151 is offline Member
    Join Date
    Jul 2012
    Posts
    55
    Rep Power
    0

    Default Re: Assign data enter by user to a 2D Array

    So the first thing you have to do is look at what is stored in the 2D array, once you find that you can just use different sorting algorithms to change the arrangement of the array.

  3. #3
    sims34 is offline Member
    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Default Re: Assign data enter by user to a 2D Array

    Thanks for the reply, but how do I find out what is stored in the array or what the user entered?

    This is what I have so far:

    public static void main(String[] args) {
    List<String> list = new ArrayList<String>();

    Scanner input = new Scanner(System.in);

    String a = "";


    while(true){

    System.out.println("Enter your data: ");
    a = input.next();

    if(a.equalsIgnoreCase("done")){
    System.out.println("Done, BYE!");


    }
    }
    }


    }


    So it asks user for data but I dont know how to get what they enter.

  4. #4
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: Assign data enter by user to a 2D Array

    How should you determine which user input goes where on the 2 dimensional field? Right now you enter a one dimensional field into an ArrayList.
    Is the 2D field of a known and/or fixed size at the beginning? Is it really a 2D field?

    You get the input in the "a" variable as string. There is no magic in adding this to your ArrayList using list.add(...), but that is not a 2D array...? So what do you want here?
    In your example you have "a" "z" as second dimension...?

    And please use the forum code tags when you post your code: Guide For New Members
    Last edited by Sierra; 01-08-2013 at 01:18 AM.
    I like likes!

  5. #5
    foulkelore is offline Member
    Join Date
    Dec 2012
    Location
    Des Moines, IA
    Posts
    35
    Rep Power
    0

    Default Re: Assign data enter by user to a 2D Array

    Too often I think people try and solve the whole problem at once. Take it in steps, one at a time. Keep compiling and testing. This will help when you run into problems. Its in the code you just wrote.

Similar Threads

  1. How do i allow user to enter ammount?
    By Diehardwalnut in forum New To Java
    Replies: 3
    Last Post: 09-27-2012, 07:54 AM
  2. Replies: 1
    Last Post: 08-29-2012, 02:00 AM
  3. How to ERROR if user presses Enter?
    By net2chris in forum New To Java
    Replies: 3
    Last Post: 10-03-2011, 06:30 PM
  4. RegardingSgould Enter in user defined inbox
    By Prashant.surwade in forum CLDC and MIDP
    Replies: 0
    Last Post: 09-23-2009, 02:21 PM
  5. Replies: 21
    Last Post: 06-11-2009, 03:18 AM

Posting Permissions

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