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.
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.
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.
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: http://www.java-forums.org/forum-gui...w-members.html
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.