【发布时间】:2021-09-28 06:34:26
【问题描述】:
如何打印二维数组 ex. 中的特定行或列。我想打印第 2 列中的行 它应该是“IJKL”或打印第 3 行中的列,它应该是“DHLP”
import java.util.Scanner;
public class Test2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String[][] word = {{"A", "B", "C", "D", },
{"E", "F", "G", "H", },
{"I", "J", "K", "L", },
{"M", "N", "O", "P", }};
for (int row = 0; row < word.length; row++) {
for (int col = 0; col < word[row].length; col++) {
System.out.print(word [row][col] + " ");
}
System.out.println();
}
}
}
【问题讨论】:
标签: java multidimensional-array