Printing a 2D array multiple times depending on user input
I posted about this assignment before, and I have the program pretty much
working with the exception of one thing. The program asks the user what
file they want to print, how many times they want to tile it across and
how many times they want to tile it down. My program reads the file into a
2d array, and then it is supposed to tile it out. I am using three for
loops to try to print it and it is printing the correct amount, however it
is only printing vertically. I tried putting in a blank println to see if
that would get it to print correctly but it is not working. Anyone have
any ideas? Here's the part of the code that stores the txt file into the
2d array and the method that is supposed to tile it:
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();
}
}
}
}
No comments:
Post a Comment