Hi, it has been awhile since programming in java and now i need it again. I am trying to load and print a 3 by 3 array to start, then add more logic later. I just cant seem to get it correct to load and print. I attatched the file.
Thanks
Printable View
Hi, it has been awhile since programming in java and now i need it again. I am trying to load and print a 3 by 3 array to start, then add more logic later. I just cant seem to get it correct to load and print. I attatched the file.
Thanks
Your code:
Please see my comments, especially the one about the while(...) statement. Think about it, and how it can introduce a very bad bug in your program. Come back if you are confused or if this helps.Code:import java.io.*;
public class Puzzle
{
public static void main(String[] args) throws IOException
{
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader keyInput = new BufferedReader(reader);
Integer[][] current = new Integer[3][3];
Integer[][] ending = new Integer[3][3];
int size = 0;
System.out.println("Type in the integers from top to bottom of each"
+ " column from left to right for a 3X3 with a 0 for the blank.");
System.out.println(" Press enter after each integer entered.");
String line = null;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
while (size != 9) // Why this while statement??????
{
line = keyInput.readLine();
current[i][j] = new Integer(line);
size++;
}
}
}
for (int k = 0; k < 3; k++)
{
for (int l = 0; l < 3; l++)
System.out.print(current[l][l]); // don't forget "k" here!
}
}
}
well thanks that got me straightened out for now.
cool. glad it helped.
If you have solve the problem please mark the thread as solved. It's really helpful to others.
Try not to confuse while with if, it's a common made mistake with beginning programmers.