
Untitled
By: a guest on Jan 28th, 2012 | syntax:
None | size: 1.62 KB | hits: 14 | expires: Never
public class Project {
public static void main(String[] args) throws Exception{
final int ROWS = 31;
final int COLS = 31;
int[][] matrix = new int[ROWS][COLS];
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the path of the file (include .txt): ");
String input;
input = keyboard.nextLine();
FileReader fr = new FileReader(input);
BufferedReader br = new BufferedReader(fr);
String s;
while((s = br.readLine()) != null)
{
String s1, s2;
int ix = s.indexOf(',');
s1 = s.substring(0, ix);
s2 = s.substring(ix+2, s.length());
int i1 = Integer.parseInt(s1);
int i2 = Integer.parseInt(s2);
int i = i1-1;
int j = i2-1;
matrix [i][j] = 1;
matrix [j][i] = 1;
}
fr.close();
//Check if the graph is connected or disconnected
int[] holdingMatrix1 = new int[31];
for (int i = 0; i < 31; i++){
holdingMatrix1[i] = 0;
System.out.print(holdingMatrix1[i] + "");
}
for(int a = 0; a < ROWS; a++){
int b=0;
matrix[a][b] = holdingMatrix1[a];
for(int z = 0; z < COLS; z++)
matrix[a][b] = holdingMatrix1[z];
} /*not correct method probably*/
//---------------------------------------------------------------------
//Rectangular representation of the 2d matrix to check if working correctly
for (int a =0; a < ROWS; a++) {
for (int b = 0; b < COLS; b++) {
System.out.print(" " + matrix[a][b]);
}
System.out.println("");
}
//---------------------------------------------------------------------
}
}