Results 1 to 2 of 2
Thread: arrays
- 08-06-2010, 05:37 AM #1
Member
- Join Date
- Aug 2010
- Posts
- 2
- Rep Power
- 0
arrays
im suppose 2 use an array to code followin infoJava Code:public static void main(String[] argv) { int[][] ia = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; System.out.println("Sum of first level: " + sumIntArray(ia[0])); System.out.println("Sum of this 2d array: " + sumIntArray(ia)); } public static int sumIntArray(int[] ia) { int result = 0; for (int i: ia) { result += i; } return result; } // And to add another dimension public static int sumIntArray(int[][] ia) { int result = 0; for (int[] i: ia) { result += sumIntArray(i); } return result; }
{ "3xcvbn", "John Doe", "34232" },
{ "2129uio", "Bill Reb", "90323" },
{ "3898qas", "Eric Quick", "10021" },
{ "hjd2314", "Bob Bark", "91920" },
2 datas with number ex (1,12,3,2,)(2,3,4,4)
i know i can use the code about to add the sums of the 2 datas but how do i make an array 4 the data above... i tried int[][] but i keep gettin errors
- 08-06-2010, 06:29 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Can you explain bit more what you really want to do? What you want to add really, third element on each array you've mentioned above?
Similar Threads
-
store array of arrays in array of arrays
By joost_m in forum New To JavaReplies: 4Last Post: 04-19-2010, 10:32 AM -
Arrays.sort... why sorting all arrays in class?
By innspiron in forum New To JavaReplies: 6Last Post: 03-23-2010, 01:40 AM -
Arrays
By HosHos in forum New To JavaReplies: 3Last Post: 08-14-2009, 04:23 AM -
Need help with 2D arrays...
By rrsv2 in forum New To JavaReplies: 3Last Post: 11-30-2008, 03:15 AM -
Need help with Arrays
By dietgal in forum New To JavaReplies: 21Last Post: 10-08-2008, 01:59 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks