题解 | #蛇形矩阵#
蛇形矩阵
https://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e
import java.util.*; public class Main { public static void main(String[] args) { Scanner fzhinput = new Scanner(System.in); int num = fzhinput.nextInt(); int sum=0,sz=1,n=1; for(int i=1;i<=num;i++){ int x=i; sum+=x; } for(int j=1;j<=num;j++){ for(int i=j+1;i<=num+1;i++){ System.out.print(sz+" "); sz+=i; } System.out.println(); n+=j; sz=n; } } }