解题思路:
注意事项:
参考代码:
import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a[][] = new int[n][n]; int x = 0, y = 0, t = 0; int d = y; t = a[x][y] = 1; while (x != n - 1) { if (y == 0) { y = x + 1; d = y; x = 0; } for (int i = 0; i <= d; i++) { t = t + 1; a[y][x] = t; if (i != d) { x = x + 1; y = y - 1; } } } for (int i = 0; i < a.length; i++) { for(int j=0;j<n-i;j++) { System.out.print(a[i][j] + " "); } System.out.println(); } } }
0.0分
1 人评分