Results 1 to 5 of 5
- 01-07-2013, 10:25 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 3
- Rep Power
- 0
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.
- 01-07-2013, 10:49 PM #2
Member
- Join Date
- Jul 2012
- Posts
- 55
- Rep Power
- 0
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.
- 01-07-2013, 11:12 PM #3
Member
- Join Date
- Jan 2013
- Posts
- 3
- Rep Power
- 0
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.
- 01-08-2013, 12:14 AM #4
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
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 MembersLast edited by Sierra; 01-08-2013 at 12:18 AM.
I like likes!.gif)
- 01-08-2013, 03:04 AM #5
Member
- Join Date
- Dec 2012
- Location
- Des Moines, IA
- Posts
- 33
- Rep Power
- 0
Similar Threads
-
How do i allow user to enter ammount?
By Diehardwalnut in forum New To JavaReplies: 3Last Post: 09-27-2012, 06:54 AM -
How to take user input from a GUI and place the data in an Array
By xkenxdizzle in forum New To JavaReplies: 1Last Post: 08-29-2012, 01:00 AM -
How to ERROR if user presses Enter?
By net2chris in forum New To JavaReplies: 3Last Post: 10-03-2011, 05:30 PM -
RegardingSgould Enter in user defined inbox
By Prashant.surwade in forum CLDC and MIDPReplies: 0Last Post: 09-23-2009, 01:21 PM -
[SOLVED] how to run loop unless and until user enter correct value
By mfaizan24 in forum New To JavaReplies: 21Last Post: 06-11-2009, 02:18 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks