1 回答

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超1個(gè)贊
試試這個(gè):
public static void main(String[] args) {
int length = 7;
int[][] numbers = new int[length][length];
int count = 1;
for(int i = 0; i < numbers.length; ++i) {
for(int j = 0; j < (i+1); ++j) {
numbers[i][j] = count++;
if(count > 9)
count = 1;
}
}
for(int i = 0; i < numbers.length; ++i) {
for(int j = 0; j < numbers.length; ++j) {
if(numbers[j][i] == 0)
System.out.print(" ");
else
System.out.print(numbers[j][i]);
System.out.print(" ");
}
System.out.println();
}
}
這會(huì)給你你的結(jié)果。請(qǐng)注意,我沒(méi)有在掃描儀中包含動(dòng)態(tài)部分。我使用長(zhǎng)度和起始編號(hào)作為常量。
說(shuō)明:在第一個(gè)循環(huán)中,我基本上只是將數(shù)字存儲(chǔ)在一個(gè)數(shù)組中。在第二個(gè)循環(huán)中,這個(gè)數(shù)組以不同的順序打印。
添加回答
舉報(bào)