So i have a file that looks like this:
+-+-+-+ ("/n")
|S| | ("/n")
+ + + + ("/n")
| |E| ("/n")
+-+-+-+ ("/n")
/n
being a new line in the file
and i want to have each character here as an entry in a 5x7 array. I do not know how to do it, this is what i have tried (along with a lot of other things. input is the file):
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(new File("maze0.txt"));
char maze[][] = new char[5][7];
int charCount = 0;
for (int row = 0; row < finalHeight; row++) {
for (int col = 0; col < finalWidth; col++) {
while (input.hasNextLine()){
String line = input.nextLine();
if ((row < finalHeight - 1 || col < finalWidth) && charCount < line.length()) {
maze[row][col] = line.charAt(charCount);
charCount += 1;
System.out.print(maze[row][col]);
But this prints out +S+ + which is not right. I am a brand new beginner programmer and having a hard time with this, thanks for any help you can offer.
I fixed it!! this is what I did:
Scanner input = new Scanner(new File("maze0.txt"));
char maze[][] = new char[5][7];
input.nextLine();
for (int row = 0; row < 5; row++) {
String fileLine = input.nextLine();
for (int col = 0; col < 7; col++) {
char nextChar = fileLine.charAt(col);
maze[row][col] = nextChar;
System.out.print(maze[row][col]);