JAVA 2차원 배열

조회수 261회
static final int ROW = 4;
static final int COL = 3;

public static void main(String[] args) {
    String[][] parkingSpace = new String[ROW][COL];

    System.out.println(" \t1\t2\t3");
    String fill = "□";

    for(int i=0; i<=parkingSpace[ROW].length + 1; i++) {
        System.out.print(i);
        for(int j=0; j<=parkingSpace[COL].length + 1; j++) {
            if(parkingSpace[i][j] != null) {
                fill = "■";
                System.out.print('\t' + fill);
            } else {
                System.out.print('\t' + fill);
            }
            }
        System.out.println();
        }

나머지가 모두 비어있고 (2, 3)에만 값이 있다고 하면 출력했을 때

    1     2     3
1   □    □    □
2   □    □    ■
3   □    □    □
4   □    □    □

로 나왔으면 합니다. 그런데 첫 줄만 출력되고 그 뒤로 오류가 납니다. 어떻게 해야 원하는 대로 출력될지 알려주셨으면 합니다.

1 답변

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)