【发布时间】:2018-04-27 01:39:18
【问题描述】:
我正在使用 java,我想根据用户输入多次水平打印二维数组。但是,我的阵列垂直打印,有人可以帮忙吗?
n=3; //user input
char[][] board = new char[2][3];
char[][] f = new char[board.length][n * board[0].length];
for (int i = 1; i < n + 1; i++) {
int Start = (i * board[0].length) - board[0].length;
int End = i * board[0].length;
for (int row = 0; row < f.length; row++) {
for (int col = nStart; col < nEnd; col++) {
f[row][col] = board[row][col - nStart];
System.out.print(f[row][col]);
}
System.out.println();
}
}
For example board array =
xx
xx
I would like
xxxxxx
xxxxxx
【问题讨论】:
-
删除
System.out.println();? -
如果您只想在每个数字之间留一个空格,请将
System.out.println()替换为System.out.print(" ")。否则删除它。 -
显示一个示例(在您的帖子中),说明您希望输出的样子。