1 回答

TA貢獻1780條經(jīng)驗 獲得超1個贊
試試這個:
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();
}
}
這會給你你的結(jié)果。請注意,我沒有在掃描儀中包含動態(tài)部分。我使用長度和起始編號作為常量。
說明:在第一個循環(huán)中,我基本上只是將數(shù)字存儲在一個數(shù)組中。在第二個循環(huán)中,這個數(shù)組以不同的順序打印。
添加回答
舉報