Results 1 to 2 of 2

Thread: arrays

  1. #1
    battosai16 is offline Member
    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

    Default arrays

    Java 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;
        }
    im suppose 2 use an array to code followin info

    { "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

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,374
    Blog Entries
    1
    Rep Power
    18

    Default

    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

  1. store array of arrays in array of arrays
    By joost_m in forum New To Java
    Replies: 4
    Last Post: 04-19-2010, 10:32 AM
  2. Arrays.sort... why sorting all arrays in class?
    By innspiron in forum New To Java
    Replies: 6
    Last Post: 03-23-2010, 01:40 AM
  3. Arrays
    By HosHos in forum New To Java
    Replies: 3
    Last Post: 08-14-2009, 04:23 AM
  4. Need help with 2D arrays...
    By rrsv2 in forum New To Java
    Replies: 3
    Last Post: 11-30-2008, 03:15 AM
  5. Need help with Arrays
    By dietgal in forum New To Java
    Replies: 21
    Last Post: 10-08-2008, 01:59 PM

Posting Permissions

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