我之前发布过这个作业,除了一件事之外,我的程序几乎可以正常工作。该程序询问用户他们想要打印什么文件,他们想要平铺多少次以及他们想要平铺多少次。我的程序将文件读入二维数组,然后应该将其平铺。我正在使用三个 for 循环来尝试打印它并且它正在打印正确的数量,但是它只是垂直打印。我尝试放入一个空白的 println 以查看它是否可以正确打印,但它不起作用。有人有想法么?这是将 txt 文件存储到 2d 数组中的代码部分以及应该平铺它的方法:
import java.io.*;
import java.util.*;
class TileMap
{
public static boolean yes;
public static char response;
public static int MAXSIDE = 100;
public static Scanner scan = new Scanner(System.in);
public static String fileName = "";
public static int tilesAcross = 0;
public static int tilesDown = 0;
public static int imageHeight = 0;
public static int imageWidth = 0;
public static char userInput = 0;
static char [][] buffer = new char[MAXSIDE][MAXSIDE];
static FileInputStream fstream = null;
public static void getImage()
{
System.out.println("Getting Image...");
try
{
File file = new File(fileName);
Scanner fstream = new Scanner(file);
imageHeight = fstream.nextInt();
imageWidth = fstream.nextInt();
buffer = new char[imageHeight][imageWidth];
int i = 0;
while(fstream.hasNextLine())
{
String line = fstream.nextLine();
for(int l = 0; l < line.length(); l++)
{
buffer[i][l] = line.charAt(l);
}
i++;
}
/*
for(int i = 0; i < imageHeight; i++)
{
String element = fstream.nextLine();
for(int j = 0; j < imageWidth; j++)
{
buffer[i][j] = element.charAt(j);
}
}
*/
fstream.close();
}
catch (Exception e)
{
System.err.println("Error: " + e.getMessage());
}
}
public static void doTileJob ()
{
for(int m = 0; m < tilesDown; m++)
{
for (int n = 0; n < tilesAcross;n++)
{
for(int i= 0; i < buffer.length; i++)
{
int w = 0;
System.out.print(buffer[i]);
System.out.println(buffer[w]);
w++;
}
System.out.println();
}
}
}
}