【发布时间】:2014-03-12 22:57:54
【问题描述】:
我正在尝试编写一个程序来读取一个数组文件(以行作为第一个字符,列作为下一个字符,然后是一个 RxC 术语框)并尝试确定是否有五个水平、垂直或对角线相邻的字符相同,颜色不同(在我的 GUI 主程序中)
代码非常慢,只适用于较小的数组?我不明白我做错了什么。
文件如下所示:
5 4
1 2 3 4 5
1 2 3 4 5
7 3 2 0 1
6 1 2 3 5
代码:
public class fiveinarow
{
int[][] Matrix = new int [100][100];
byte[][] Tag = new byte [100][100];
int row, col;
String filepath, filename;
public fiveinarow()
{
row = 0;
col = 0;
filepath = null;
filename = null;
}
public void readfile()
{
JFileChooser chooser = new JFileChooser();
chooser.setDialogType(JFileChooser.OPEN_DIALOG );
chooser.setDialogTitle("Open Data File");
int returnVal = chooser.showOpenDialog(null);
if( returnVal == JFileChooser.APPROVE_OPTION)
{
filepath = chooser.getSelectedFile().getPath();
filename = chooser.getSelectedFile().getName();
}
try
{
Scanner inputStream = new Scanner(new FileReader(filepath));
int intLine;
row = scan.nextInt();
col = scan.nextInt();
for (int i=0; i < row; i++)
{
for (int j = 0 ; j < col; j++)
{
int[][]Matrix = new int[row][col];
Matrix[i][j] = inputStream.nextInt();
}
}
}
catch(IOException ioe)
{
System.exit(0);
}
}
当我计算一个 7x7 时,我得到了打开的确认,并且处理给出了一个所有零的数组 (7x7)。 当我计算 15x14 时,我得到“线程中的异常”AWT-EventQueue-0 错误并且处理时没有数组。
【问题讨论】:
-
您似乎混合了行和列(如果您的示例数据是正确的数据)。您的示例有四行五列