JAVA 프로그래밍

문제

파일에 저장된 맵을 출력하는 문제입니다 이를 해결하는 프로그램의 다음 실행상태에 대해 빈칸을 채우세요 

프로그램의 실행순서 및 실행상태

1  public static void main( String[] args ) throws IOException {

2   String filename = scan.next();
파일이름을 입력하세요: mazemap1.txt

3   BufferedReader inFile = new BufferedReader( new FileReader( new File( filename ) ) );

5   for( String line = ""; ( line = inFile.readLine() ) != null; height++ ) {

6    if ( line.length() < 3 ) {

8    else {

9    }
 main()     mazemap1.txt
 filename inFile  →     111111111\n 
   height width    120010003\n 
line    111010111\n 
[0] [1] [2] [3] [4] [5] [6] [7] [8] ...    111010111\n 
map[0] ...    101111101\n 
   [1]  0   0   0   0   0   0   0   0   0  ...    100000001\n 
   [2]  0   0   0   0   0   0   0   0   0  ...    111111111\n 
   [3]  0   0   0   0   0   0   0   0   0  ...
   [4]  0   0   0   0   0   0   0   0   0  ...
   [5]  0   0   0   0   0   0   0   0   0  ...
   [6]  0   0   0   0   0   0   0   0   0  ...
   ... ... ... ... ... ... ... ... ... ... ...
                                       

5   for( String line = ""; ( line = inFile.readLine() ) != null; height++ ) {
                                              
... 

5   for( String line = ""; ( line = inFile.readLine() ) != null; height++ ) {

6    if ( line.length() < 3 ) {

8    else {

9    }
 main()     mazemap1.txt
 filename inFile  →     111111111\n 
   height width    120010003\n 
line    111010111\n 
[0] [1] [2] [3] [4] [5] [6] [7] [8] ...    111010111\n 
map[0]  1   1   1   1   1   1   1   1   1  ...    101111101\n 
   [1]  1   2   0   0   1   0   0   0   3  ...    100000001\n 
   [2]  1   1   1   0   1   0   1   1   1  ...    111111111\n 
   [3]  1   0   0   0   1   0   0   0   1  ...
   [4]  1   0   1   1   1   1   1   0   1  ...
   [5]  1   0   0   0   0   0   0   0   1  ...
   [6] ...
   ... ... ... ... ... ... ... ... ... ... ...
                                       

5   for( String line = ""; ( line = inFile.readLine() ) != null; height++ ) {

10   inFile.close();
                                                         
 filename               inFile

■■■■■■■■■
■옷 ■ 문
■■■ ■ ■■■
■ ■ ■
■ ■■■■■ ■
■ ■
■■■■■■■■■

11  }


프로그램 코드

	import java.io.*;
	import java.util.Scanner;
		
	public class MazeMapFile
	{
1		public static void main( String[] args ) throws IOException {
			Scanner scan = new Scanner( System.in );
			System.out.print( "파일이름을 입력하세요: " );
2			String filename = scan.next();
3			BufferedReader inFile = new BufferedReader( new FileReader( new File( filename ) ) );
			
			int[][] map = new int[100][100];
			int height = 0, width = 0;
5			for( String line = ""; ( line = inFile.readLine() ) != null; height++ ) {
6				if ( line.length() < 3 ) {
7					break;
				}
8				else {
					for( width = 0; ( width < line.length() ) && ( '0' <= line.charAt(width) ) && ( line.charAt(width) <= '9' ); width++ ) 
						map[height][width] = line.charAt(width) - '0';
9				}
			}
			
10			inFile.close();
			
			String[] symbol = { "  ", " \033[44m   \033[0m", "옷", " \033[34m문 \033[0m", " \033[31m♥ \033[0m", " \033[33m★ \033[0m", " \033[32m♣ \033[0m", " \033[31m♠ \033[0m", " \033[36m◆ \033[0m", " \033[35m■ \033[0m" };
			for( int row = 0; row < height; row++ ) {
				for( int column = 0; column < width; column++ )
					System.out.print( symbol[ map[row][column] ] );
				System.out.println();
			}
			scan.close();
11		}
	}