Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- static Scanner sc = new Scanner(System.in);
- public static void main(String[] args) {
- int n = sc.nextInt();
- System.out.println(n);
- int[][] a = new int[n][n];
- int i = 1;
- int column = a.length-1;
- while(column >= 0){
- int row = 0;
- int depth = column;
- while (depth < a.length){
- a[row][depth] = i;
- i++;
- depth++;
- row++;
- }
- column--;
- }
- int row = 1;
- while (row < a.length){
- column = 0;
- int depth = row;
- while (depth < a.length){
- a[depth][column] = i;
- i++;
- depth++;
- column++;
- }
- row++;
- }
- for (i = 0; i < n; i++){
- for (int j = 0; j < n; j++){
- System.out.print(String.valueOf(a[i][j]) + " ");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement