題目示例:(不是問題)


歡迎感興趣的程式大佬在帖子下面留言,將不定期放送Java題目供大佬們挑戰
uj5u.com熱心網友回復:
隨手寫一個吧
public class Test3 {
public static int[][] createArray(int row) {
if (row<=0) return null;
int res[][] = new int[row][];
for (int i=0; i<row; i++) {
res[i] = new int[row-i];
/*
for (int j=0; j<res[i].length; j++) {
res[i][j] = 0;
}
*/
}
return res;
}
public static void printArray(int[][] a) {
if (a==null) {
System.out.println("a is null.");
}
for (int i=0; i<a.length; i++) {
for (int j=0; j<a[i].length; j++) {
System.out.printf("%d ", a[i][j]);
}
System.out.println();
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int row = 0;
while (true) {
try {
System.out.printf("請輸入行數:");
row = sc.nextInt();
if (row<=0) throw new Exception("error.");
break;
} catch(Throwable e) {
System.out.println("輸入錯誤,請重輸。");
}
}
int[][] a = createArray(row);
printArray(a);
}
}
uj5u.com熱心網友回復:
第一次見到把白嫖說的這么好聽的??
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/69314.html
標籤:Eclipse
