Guest

Untitled

By: a guest on Jan 28th, 2012  |  syntax: None  |  size: 1.62 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. public class Project { 
  2.        
  3.         public static void main(String[] args) throws Exception{
  4.                
  5.                 final int ROWS = 31;
  6.                 final int COLS = 31;
  7.                 int[][] matrix = new int[ROWS][COLS];
  8.                
  9.                 Scanner keyboard = new Scanner(System.in);
  10.                 System.out.print("Enter the path of the file (include .txt): ");
  11.                 String input;
  12.                 input = keyboard.nextLine();
  13.                
  14.                 FileReader fr = new FileReader(input);
  15.                 BufferedReader br = new BufferedReader(fr);
  16.                 String s;
  17.                
  18.                 while((s = br.readLine()) != null)
  19.                 {
  20.                         String s1, s2;
  21.                         int ix = s.indexOf(',');
  22.                         s1 = s.substring(0, ix);
  23.                         s2 = s.substring(ix+2, s.length());
  24.                         int i1 = Integer.parseInt(s1);
  25.                         int i2 = Integer.parseInt(s2);
  26.                        
  27.                         int i = i1-1;
  28.                         int j = i2-1;
  29.                         matrix [i][j] = 1;
  30.                         matrix [j][i] = 1;
  31.                 }
  32.                 fr.close();
  33.                
  34.                
  35.                 //Check if the graph is connected or disconnected
  36.                 int[] holdingMatrix1 = new int[31];
  37.                 for (int i = 0; i < 31; i++){
  38.                         holdingMatrix1[i] = 0;
  39.                         System.out.print(holdingMatrix1[i] + "");
  40.                 }
  41.                
  42.                 for(int a = 0; a < ROWS; a++){
  43.                         int b=0;
  44.                         matrix[a][b] = holdingMatrix1[a];
  45.                         for(int z = 0; z < COLS; z++)
  46.                         matrix[a][b] = holdingMatrix1[z];
  47.                 } /*not correct method probably*/
  48.                
  49.                
  50.                
  51.                
  52.                
  53.                 //---------------------------------------------------------------------
  54.                 //Rectangular representation of the 2d matrix to check if working correctly
  55.                 for (int a =0; a < ROWS; a++) {
  56.                     for (int b = 0; b < COLS; b++) {
  57.                         System.out.print(" " + matrix[a][b]);
  58.                     }
  59.                     System.out.println("");
  60.                 }
  61.                 //---------------------------------------------------------------------
  62.                
  63.                
  64.                
  65.                
  66.                
  67.                
  68.         }
  69. }