Java Question

How can i print just a single column from a two dimensional array?

I have this program im writing and i have to print just one column of a two dimensional array, not both.

for (int i = 0; i < sjf.length; i++)
{
for(int j = 0; j < sjf[i].length; j++)
{
System.out.printf("%5d%4s ", sjf[i][j], "|");
}
System.out.println();
}
System.out.println();

Answer

For example you want to print the fifth column:

int column = 5;
for (int[] row : sjf) {
       System.out.printf("%5d%4s   ", row[column], "|");
}
System.out.println();
Comments