자연수 n을 입력받아 "출력 예"와 같이 n x n크기에 공백으로 구분하여 출력되는 프로그램을 작성하시오.
10 미만의 홀수만 출력하시오.
주의! 숫자는 공백으로 구분하되 줄사이에 빈줄은 없다.
3
package com.jungol.algorithm115;
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 a = 0;
for(int i = 0; i < inputNumber; i++) {
for(int j = 1 + a; j <= ((2 * inputNumber) - 1 + a); j+=2) {
cnt+=2;
if(j > 10) {
System.out.print((j % 10) + " ");
} else {
System.out.print(j + " ");
}
}
a = cnt;
System.out.println();
}
sc.close();
}
}