您可以嘗試使用循環再生:
String[][] example = new String[][] { { "a", "b", "c", "d" }, { "e", "f", "g", "h" } };
for (int row = 0; row < example.length; row++) {
for (int column = 0; column < example[row].length/2; column++) {
System.out.print(" " + example[row][column] + "\t|");
}
System.out.println();
}
System.out.println("----------------------------------------");
for (int row = 0; row < example.length/2; row++) {
for (int column = 0; column < example[row].length; column++) {
System.out.print(" " + example[row][column] + "\t|");
}
System.out.println();
}
System.out.println("----------------------------------------");
for (int row = example.length/2; row < example.length; row++) {
for (int column = 0; column < example[row].length; column++) {
System.out.print(" " + example[row][column] + "\t|");
}
System.out.println();
}
System.out.println("----------------------------------------");
for (int row = 0; row < example.length; row++) {
for (int column = example[row].length/2; column < example[row].length; column++) {
System.out.print(" " + example[row][column] + "\t|");
}
System.out.println();
}
System.out.println("----------------------------------------");
for (int row = 0; row < example.length; row++) {
for (int column = example[row].length/4; column < example[row].length; column++) {
System.out.print(" " + example[row][column] + "\t|");
}
System.out.println();
}
System.out.println("----------------------------------------");
for (int row = 0; row < example.length; row++) {
for (int column = example[row].length * 3/4; column < example[row].length; column++) {
System.out.print(" " + example[row][column] + "\t|");
}
System.out.println();
}
System.out.println("----------------------------------------");
輸出:
a | b |
e | f |
----------------------------------------
a | b | c | d |
----------------------------------------
e | f | g | h |
----------------------------------------
c | d |
g | h |
----------------------------------------
b | c | d |
f | g | h |
----------------------------------------
d |
h |
----------------------------------------
第一個問題:什麼季度? – tadman
只是一般印刷只有某些部分,如有10行和colums如何,我會打印最後2行和最後2 colums –
@ hephaestus哈迪斯可以用你的2D陣列更新帖子。這將有助於給出答案。 – Dev4World