Re: Array declaration syntax question
From: Thomas G. Marshall (tgm2tothe10thpower_at_hotmail.replaceTextWithNumber.com)
Date: 10/17/03
- Next message: David Segall: "Re: Outsourcing to India and China"
- Previous message: Vjeran Marcinko: "Re: Mutual EJB possible?"
- In reply to: Thomas G. Marshall: "Re: Array declaration syntax question"
- Next in thread: Gordon Beaton: "Re: Array declaration syntax question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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();
- Next message: David Segall: "Re: Outsourcing to India and China"
- Previous message: Vjeran Marcinko: "Re: Mutual EJB possible?"
- In reply to: Thomas G. Marshall: "Re: Array declaration syntax question"
- Next in thread: Gordon Beaton: "Re: Array declaration syntax question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|