By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,798 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,798 IT Pros & Developers. It's quick & easy.

Print an array by column help.

P: n/a
I have two arrays:

int array1[][] = { { 1, 2, 3 },
{ 4, 5, 6 } };

int array2[][] = { { 1, 2 },
{ 3 },
{ 4, 5, 6 } };

I need to print both of them by column like this:

1 4
2 5
3 6

and

1 3 4
2 5
6

I can do the first one, but I can't seem to use array.length and array[
row ].length to print the array by columns. Thanks.
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Stephen" <se*******@hotmail.com> wrote in message
news:jG*************@newsread2.news.atl.earthlink. net...
I have two arrays:

int array1[][] = { { 1, 2, 3 },
{ 4, 5, 6 } };

int array2[][] = { { 1, 2 },
{ 3 },
{ 4, 5, 6 } };

I need to print both of them by column like this:

1 4
2 5
3 6

and

1 3 4
2 5
6

I can do the first one, but I can't seem to use array.length
and array[row].length to print the array by columns. Thanks.


Try:

for (int row = 0; row < array1.length; ++row)
{
for (int col = 0; col < array1[row].length; ++col)
System.out.print(array1[row][col] + ' ');
System.out.println();
}

I hope this helps.

Anthony Borla
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.