자연수 n을 입력받아 "출력 예"와 같이 공백으로 구분하여 출력되는 프로그램을 작성하시오.
주의! 숫자는 공백으로 구분하되 줄사이에 빈줄은 없다.
3
package com.jungol.algorithm113;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int inputNumber = sc.nextInt();
int cnt = 0;
int cnt2 = 0;
int cnt3 = 0;
int a = 0;
for(int i = 0; i < inputNumber; i++) {
//공백
for(int j = 0; j < cnt3; j++) {
System.out.print(" ");
}
cnt3+=2;
//숫자
for(int j = 1 + a; j <= inputNumber + a - cnt2; j++) {
System.out.print(j + " ");
cnt++;
}
a = cnt;
cnt2++;
System.out.println();
}
sc.close();
}
}