- public class Test3 {
- /*
- * 打印输出
- * 1 3 6 10 15
- * 2 5 9 14
- * 4 8 13
- * 7 12
- * 11
- */
- public static void main(String[] args) {
- int result;
- for (int i = 1; i <= 5; i++) {
- //先求出每行第一个数值 result
- //经观察发现,result与计数器i存在以下关系(向下寻找最近的//之前的语句)
- result=0;
- for (int k = 1; k < i; k++) {
- result+=k;
- }
- result++;
- //
- //add为递加值,
- int add=i+1; //每行第一个递加值与计数器关系!
- for (int j = 1; j <=6-i; j++) {
- System.out.print(result+" ");
- result+=add;
- add++; //递加值add每次加1
- }
- System.out.println();
- }
- }
- }