승현0604 2023. 3. 28. 19:28

종류 1. 열이 한번바귈때마다 숫자를 높여주면된다.

종류 2.  전문제와 똑같이 열이 바뀔때마다 숫자를 1로 초기화해주어 배열에 넣어주는 방식으로 했다

종료 3. 하나의 열에 전부 12345로 초기화해주고 각 열에 그 숫자만큼 더하게끔 해주었다. 

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int cnt = 1;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int arr[][] = new int[n][n];

		switch (m) {
		case 1:
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					System.out.print(cnt+" ");
				}
				cnt++;
				System.out.println();
			}break;
		case 2:	
			int cnt2 = 1;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if(i % 2 == 1) {
						cnt2--;
						arr[i][j] = cnt2;
					}else {
						arr[i][j] = cnt2;
						cnt2++;
					}
				}
			}
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					System.out.print(arr[i][j]+" ");
				}
				System.out.println();
			}
			break;
		case 3:
			int cnt3 = 1;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if(i == 0) {
						arr[i][j] = cnt3++;
					}else {
						arr[i][j] = arr[0][j] * (i + 1);
					}
				}
			}
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					System.out.print(arr[i][j] + " ");
				}
				System.out.println();
			}
		default:
			break;
		}
	}
}