JAVA 2차원 배열
조회수 263회
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 □ □ □
로 나왔으면 합니다. 그런데 첫 줄만 출력되고 그 뒤로 오류가 납니다. 어떻게 해야 원하는 대로 출력될지 알려주셨으면 합니다.
댓글 입력