Re: Array declaration syntax question

From: Thomas G. Marshall (tgm2tothe10thpower_at_hotmail.replaceTextWithNumber.com)
Date: 10/17/03


Date: Fri, 17 Oct 2003 15:30:40 GMT

Thomas G. Marshall <tgm2tothe10thpower@hotmail.replaceTextWithNumber.com>
coughed up the following:

...[self snippage]...

        [Remember that this technique is in addition to the other
        techniques explained, not in replacement of. In addition,
        this technique is particularly well suited to the need for
        box arrays with only a /few/ rows of odd lengths.]

It occurred to me that my example might not be enough for a newbie. I
specifically fill a box with 9 and then print the entirety of the array of
arrays, which has a leg of 15 elements, which are 0, to show the parts of
the original box array and the extra elements of row 2.

Perhaps it would have been clearer if I had filled the entire thing with
9's. This is an example where the fill loop is changed to:

        for (int y=0; y < a.length; y++)
            for (int x=0; x < a[y].length; x++)
                a[y][x] = 9;

Producing:

        9 9 9 9 9 9 9
        9 9 9 9 9 9 9
        9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
        9 9 9 9 9 9 9
        9 9 9 9 9 9 9

...and this is all the code:

        int xSize = 7;
        int a[][] = new int[5][xSize];

        a[2] = new int[15];

        for (int y=0; y < a.length; y++)
            for (int x=0; x < a[y].length; x++)
                a[y][x] = 9;

        for (int y=0; y < a.length; y++)
        {
            for (int x=0; x < a[y].length; x++)
                System.out.print(a[y][x]+" ");
            System.out.println();
        }
        System.out.println();



Relevant Pages

  • Re: Redim
    ... >> The maximum upper bound of an array is a Long value which would ... >The Out Of Memory error occurs instantly, ... you ReDim it and then remove any extra elements once you have all of ...
    (microsoft.public.vb.general.discussion)
  • Re: Challenge: reading ascii data
    ... to store all the data before producing any output. ... Here is a Ruby ... So I use hashes to create a two-level "sparse array", ... Well the original problem definition was: ...
    (comp.lang.fortran)
  • Re: draw dependency graphic
    ... > I'm a newbie to graphic theory. ... > input is a description of dependency graphic in array or XML. ... earlier versions were available at no charge. ...
    (comp.unix.programmer)
  • Re: Using a variable as output filename
    ... Plese help a newbie! ... filehandle one line at a time instead (never using an array). ...
    (perl.beginners)
  • Re: Word-processing benchmark anyone?
    ... > producing bible.txt file containing ... > 4,947,047 chars. ... > word occurances in count array. ...
    (comp.lang.fortran)