JAVA 프로그래밍

문제

파일에 저장된 맵을 출력하는 문제입니다 실행순서를 클릭하세요 
--------- 파일 mazemap1.txt의 내용 --------- 
111111111
120010003
111010111
100010001
101111101
100000001
111111111
--------- 파일 mazemap2.txt의 내용 --------- 
1111111111111111111111111
1200000516000000170000001
1000000010000000100000001
1000000010000000100000001
1111011111115111111181111
0000000000000000000000043
1111711111119111111161111
1000000410000000100000001
1000000010000000100000001
1000000010000008190000001
1111111111111111111111111
--------- 파일 mazemap3.txt의 내용 --------- 
00000000000000000000000000000000000000000000000000000000
20000000000000000000000000000004000000000000000000000000
11111111100000000000000000011111100000000000000000000000
00000000000000000000000000000000000000000000000000000003
00000000111110000011111111110000000111111111100001111111
40000000000000000000000000000000000000000000000000040000
11111111100011111111111111111111111110000000111111111000
파일이름을 입력하세요: C:\Users\user\Downloads\mazemap1.txt

프로그램 코드

	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		}
	}








 
실행 순서