Note that there are some explanatory texts on larger screens.

plurals
  1. POFinding Connected Components and reading an adjacency matrix
    text
    copied!<p>This is actually my first post here. I wasn't aware of this website, and I lurked around the questions and its certainly a place I want to keep coming to.</p> <p>I'm in my Senior year for Computer Science but my programming skills are not that good, which makes me feel very disappointed in myself. </p> <p>Anyways, I have a project due on Friday and I've been working on it since Saturday and I keep bashing my head making no progress.</p> <p>I need to find the connected components in a graph and also read from a file an adjacency matrix.</p> <p>I first tried in in python, using an igraph python library but I just kept having system errors. So after two days of trying to troubleshoot that, I gave up and moved onto Java where I'm trying to read the array.</p> <p>Here is my current code that I have thus far, and I'm trying to google the best I can to find the answer. Right now I'm simply trying to read from a file and put the values into my 2d array. I commented out most of everything because I'm trying to simply figure out what I'm doing wrong.</p> <pre><code>package javaapplication1; import java.io.*; import java.util.Scanner; import tio.*; public class JavaApplication1 { public static void adjMatrix() throws FileNotFoundException, IOException{ int i, j, n = 20; int[][]array = new int[n][n]; String file = ("adjmatrix.txt"); BufferedReader in = new BufferedReader(new FileReader(file)); System.out.println(in.readLine()); in.close(); /* while(in.hasMoreElements()){ for (i = 0; i &lt; n; i++){ for (j = 0; j &lt; n; j++){ array[i][j] = in.readInt(); } // end inner for } // end outer for } //Print array System.out.println("Here is the matrix: "); for (i = 0; i &lt; n; i++){ for (j = 0; j &lt; n; j++){ System.out.print(array[i][j]); } // end innerfor } //end outerfor */ } // endclass /** * @param args the command line arguments */ public static void main(String[] args) throws IOException{ adjMatrix(); } // end main } // end class </code></pre> # <p>ERROR: Exception in thread "main" java.io.FileNotFoundException: adjmatrix.txt </p> <p>(The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(FileInputStream.java:138) at java.io.FileInputStream.(FileInputStream.java:97) at java.io.FileReader.(FileReader.java:58) at javaapplication1.JavaApplication1.adjMatrix(JavaApplication1.java:26) at javaapplication1.JavaApplication1.main(JavaApplication1.java:60) Java Result: 1 BUILD SUCCESSFUL (total time: 0 seconds)</p> #
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload