如何读取带有字符的文件,并将它们放入2D int数组中?

时间:2016-11-30 12:29:11

标签: java arrays conways-game-of-life

我试图通过阅读文件来编写生命游戏,每个文件都有自己的闪光灯写成星号,然后我会阅读,如果有星号则只分配给数组元素。

例如:

int [] [] grid = new int [x][y];    
        Scanner file = new Scanner(new File("file.txt"));
        int count;
        int charCount;
        int x;
        int y;

        for (count =0 ; file.hasNext();count++ )                    
        {
            file.nextLine();            
            x = count;                                                  
            for(charCount = 0; file.hasNext(); charCount++);                        
                file.findInLine("*").charAt(charCount);
                y = charCount;

在伪代码中:

for each row in rows
  read row from file
for each character in row
    check if character is an asterisk
        set value of integer array at row, col

0 个答案:

没有答案