본문 바로가기
알고리즘 문제연습/기초 알고리즘

[011] 숫자 사각형 출력하기

by 은z 2021. 5. 19.

문제

- 입력된 수만큼 n행 n열의 형태로 연속으로 출력되는 숫자 사각형을 구현하세요

- 반복문 이용

 

보완할 점

 

 

소스코드

public class Algorithm10 {

	public static void main(String[] args) {
		int num = 5;
		
		for(int i = 1; i <= num * num; i++) {
			System.out.print(i + "  ");
			if(i % num == 0) {
				System.out.println();
			}
		}
	}

}

댓글