title: creating 2 dimensional array from text file
body: <p>I am trying to add values into a 2d array from a text file. I cannot figure out how to convert the input file to teacher's array format. The file contains a first line that goes into an array that represents vertices. That part works fine. Every line after the first line contains numbers for the adjacency matrix. These numbers are read in but for some reason the slots in the matrix are not being filled. I need to use those numbers to fill a double array that would be the same as using this statement:</p>
  
  <pre><code>int[][] edges = {
  
          {0,1}, {0,2},
  
          {1,0},{1,2},
  
          {2,0},{2,1},{2,3},{2,4},{2,6},
  
          {3,2},{3,4},{3,5},
  
          {4,2},{4,3},
  
          {5,3},{5,6},
  
          {6,2},{6,5},{6,7},
  
          {7,6}
  </code></pre>
  
  <p>I have to read input from a txt file. The names represent the names of the nodes or vertices in my graph. The numbers represent the positions of the vertices in an adjacency matrix. For example the first line represents row o which maps to node john, and it means that john is connected by an edge to node 1 and 2 which are peter and mary. The numbers should map the same way as the array creation above. Here is what the file looks like :</p>
  
  <pre><code>john;peter;mary;susan;george;debbie;tom;bill;
  
  0 1 2
  
  1 0 2
  
  2 0 1 3 4 6
  
  3 2 4 5
  
  4 2 3
  
  5 3 6
  
  6 2 5 7
  
  7 6
  </code></pre>
  
  <p>And here is my code :</p>
  
  <pre><code>import java.io.File;
  import java.io.FileNotFoundException;
  import java.util.Scanner;
  
  
  public class TestSocialGraph {
  public static void main(String args[]){
      String verts;
      int[][] edges;
      int[] intPasser;
      File input = new File("GraphInput.txt");
      String[] names;
      try {
          Scanner reader = new Scanner(input);
      verts = reader.next();
      names = verts.split(";");
      edges = new int[names.length][names.length];
  
      while (reader.hasNextLine()){
          int b = 0;
          int count = 0;
      String passer = reader.nextLine();
  //  System.out.println(passer);
      String[] temp = passer.split(" ");
      intPasser = new int[temp.length];
  
  
      for(int i = 1; i&lt; temp.length; i++){
          System.out.println(temp[i]);
              intPasser[b] = Integer.parseInt(temp[i]);
  
          b++;
          }
      System.out.println(intPasser[0]);
      for(int i = 0; i&lt; intPasser.length; i++){
  
          edges[count][intPasser[i]] = 1;
  
      }
      count++;
      }
  
  
      } catch (FileNotFoundException e) {
          System.out.println("File not found. Please place appropriate file and restart program");
          System.exit(1);
      }
  }
  }
  </code></pre>