Results 1 to 8 of 8
- 02-03-2010, 04:25 AM #1
Member
- Join Date
- Oct 2009
- Posts
- 27
- Rep Power
- 0
-
Wishing you much luck with that.
Note that if you have an actual question, I strongly suggest that you do that, ask a question (I don't see one above), and also provide enough information so that it's answerable (right now as far as details, you don't give much). So again, about all I can do is wish you luck. :)Last edited by Fubarable; 02-03-2010 at 04:45 AM.
- 02-03-2010, 06:24 AM #3
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
- 02-03-2010, 06:52 AM #4
Member
- Join Date
- Jan 2010
- Posts
- 26
- Rep Power
- 0
Enjoy, ofcouse the simplest case is to say new int[1][size] but thats a bit cheecky no?Java Code:int size = arrlist.size(); secondSize = size /2; int secondSize = size%2 == 0 ? secondSize : secondSize+1; int[][] intArray = new int[2][secondSize]; for(int i=0;i<size;i++){ if(i > secondSize){ intArray[1][i%secondSize] = arrlist.get(i); } else{ intArray[0][i]=arrlist.get(i); } }
- 02-03-2010, 06:53 AM #5
Member
- Join Date
- Jan 2010
- Posts
- 26
- Rep Power
- 0
On a second look that i > secondSize may need to be >=
- 02-03-2010, 06:56 AM #6
Member
- Join Date
- Jan 2010
- Posts
- 26
- Rep Power
- 0
may need a intValue() call as well
- 02-03-2010, 07:28 AM #7
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
- 02-04-2010, 11:09 AM #8
Member
- Join Date
- Jan 2010
- Posts
- 26
- Rep Power
- 0
Just stick that in a main and see for yourself, had to fix the 2nd and third line of the original, the int is on the wrong line.Java Code:/* declare a list and fill it */ ArrayList<Integer> arrlist = new ArrayList<Integer>(); arrlist.add(3); arrlist.add(4); arrlist.add(5); arrlist.add(10); arrlist.add(2); arrlist.add(23); arrlist.add(1); /* Original Code with a few fixes */ int size = arrlist.size(); int secondSize = size / 2; secondSize = size % 2 == 0 ? secondSize : secondSize + 1; int[][] intArray = new int[2][secondSize]; for (int i = 0; i < size; i++) { if (i >= secondSize) { intArray[1][i % secondSize] = arrlist.get(i); } else { intArray[0][i] = arrlist.get(i); } } /* foreach loop on the multidimensional array */ for(int[] i : intArray){ for(int j : i){ System.out.println("A Number in the array " + j); } }Last edited by JavaJuJitZu; 02-04-2010 at 11:09 AM. Reason: typo
Similar Threads
-
file input: array of integers
By hannes in forum New To JavaReplies: 8Last Post: 01-27-2010, 03:44 PM -
Error if array contains duplicate integers
By lithium002 in forum New To JavaReplies: 4Last Post: 12-05-2009, 08:58 AM -
Help with Code! Display Array of Strings and Integers - Sorted
By luvjoynt in forum New To JavaReplies: 7Last Post: 04-28-2008, 04:28 AM -
return Set .toArray(); method as an array of integers
By maxim in forum New To JavaReplies: 2Last Post: 04-16-2008, 12:35 PM -
Arraylist to a 2- dimension array conversion
By mars123 in forum New To JavaReplies: 1Last Post: 12-06-2007, 11:24 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks