题解 | #蛇形矩阵#
蛇形矩阵
https://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int numLine = scanner.nextInt(); for (int i = 0; i < numLine; i++) { int begin = 1+i*(i+1)/2; System.out.print(begin + " "); for (int j = 0; j < numLine-i-1; j++) { System.out.print((begin+=(j+i+2)) + " "); } System.out.print("\n"); } } }