View Code of Problem 57

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int get = scanner.nextInt();
        for (int i = 0; i < get; i++) {
            for (int j = 0; j < get - i - 1; j++) {
                System.out.print(" ");
            }
            for (int j = 0; j <= i; j++) {
                System.out.print(j + 1);
            }
            for (int j = i - 1; j >= 0; j--) {
                System.out.print(j + 1);
            }
            System.out.println();
        }

        for (int i = get - 1; i > 0; i--) {
            for (int j = i; j < get; j++) {
                System.out.print(" ");
            }
            for (int j = 0; j < i - 1; j++) {
                System.out.print(j + 1);
            }
            for (int j = i - 1; j >= 0; j--) {
                System.out.print(j + 1);
            }
            if (i > 1) {
                System.out.println();
            }
        }

    }
}

Double click to view unformatted code.


Back to problem 57