2017-01-09 61 views
-1

我试图通过从文件中获取以下坐标并将其找到从0到1的方式,将这些放入ArrayList中,然后从int 0开始并找到它与之连接的内容,以及将1搜索0到1的值java

11 3 
2 3 
0 3 
1 4 
5 4 
5 7 
6 7 
7 8 
8 9 
9 10 
0 5 

到目前为止,我所做的是从获取文件中的值,并把它变成ArrayList中,

ArrayList<String[]> listValues = new ArrayList<String[]>(); 
ArrayList<String> resultSet= new ArrayList<String>(); 
try{ 

    String line = null; 
    String fileName =("C:\\Users\\Kamran Ali\\Documents\\NetBeansProjects\\TestMazeDone\\maze1.txt"); 
    System.out.println("File: " +fileName); 
    BufferedReader br = new BufferedReader(new FileReader(fileName)); 
    while ((line = br.readLine())!= null) 
    { 
     String[] locations = line.split(" "); 
     listValues.add(locations); 
    } 
    br.close(); 

} 
//Handling File not found or Path Error Exceptions 
catch(FileNotFoundException ex){ 
    System.out.println("Specified file does'nt exist"); 
} 
//Handling Input/Output Exceptions 
catch(IOException ex){ 
    System.out.println("There was an error, please try again"); 
} 

我没有任何线索如何做到的休息,这就是:

  1. 找到0 int。
  2. 找到0 INT的相邻值,
  3. 发现,INT的相邻值,并放入数组...并继续下去,直到INT 1
  4. 打印出数组。

输出的上述文件应该是这样的: [0 5 4 1]

+0

你的问题不清楚。我没有看到任何试图从你写这(只有解析)。改进您的示例并查看一些遍历算法以获得一些想法。 – AxelH

+0

是的,谢谢。但是编程不好,所以我没有任何关于h/ow比较的想法,并且在我的arrayllist中找到0的下一个值。也许是一个for循环 –

回答