알고리즘/알고리즘 기초 100제
문제10-숫자 사각형 출력
가다파하
2020. 7. 22. 00:25
문제: 입력된 수(N)만큼 N행 N열 형태로 출력되는 사각형을 만드세요.
예) 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
import java.util.Scanner;
public class Study10 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for (int i = 1; i <= n; i++) {
for (int j = (-1 * n + 1); j < 1; j++) {
System.out.printf("%4d", (i * n) + j);
}
System.out.println();
}
/*for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
System.out.printf("%4d", i*n+1);
}
}*/
}
}
출처 : youtu.be/NldRYbDqgKw