如何从二维数组中仅打印一列? [英] How can i print just a single column from a two dimensional array?

查看:368
本文介绍了如何从二维数组中仅打印一列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写此程序,我只需要打印二维数组的一列,而不能全部打印.

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();

推荐答案

例如,您要打印第五列:

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();

这篇关于如何从二维数组中仅打印一列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆