LineNumberReader lnr = new LineNumberReader(r); String line; int currentRow = -1;  while ((line = lnr.readLine()) != null) {  if (line.startsWith("%")) { continue; } StringTokenizer st = new StringTokenizer(line); if (!st.hasMoreTokens()) { continue; }  if (currentRow < 0) { int rows = Integer.parseInt(st.nextToken()); if (!st.hasMoreTokens()) { throw new Exception("Line " + lnr.getLineNumber() + ": expected number of columns"); } int cols = Integer.parseInt(st.nextToken()); m_Elements = new double [rows][cols]; initialize(); currentRow ++; continue;  } else { if (currentRow == numRows()) { throw new Exception("Line " + lnr.getLineNumber() + ": too many rows provided"); } for (int i = 0; i < numColumns(); i++) { if (!st.hasMoreTokens()) { throw new Exception("Line " + lnr.getLineNumber() + ": too few matrix elements provided"); } m_Elements[currentRow][i] = Double.valueOf(st.nextToken()) .doubleValue(); } currentRow ++; } } if (currentRow == -1) { throw new Exception("Line " + lnr.getLineNumber() + ": expected number of rows"); } else if (currentRow != numRows()) { throw new Exception("Line " + lnr.getLineNumber() + ": too few rows provided"); }
m_Elements = new double[nr][nc]; initialize();
  public Matrix(Reader r) throws Exception {    LineNumberReader lnr = new LineNumberReader(r);    String line;    int currentRow = -1;    while ((line = lnr.readLine()) != null) {      if (line.startsWith("%")) { // Comments	continue;      }      StringTokenizer st = new StringTokenizer(line);      if (!st.hasMoreTokens()) {  // Ignore blank lines	continue;      }      if (currentRow < 0) {	int rows = Integer.parseInt(st.nextToken());	if (!st.hasMoreTokens()) {	  throw new Exception("Line " + lnr.getLineNumber() 			      + ": expected number of columns");	}	int cols = Integer.parseInt(st.nextToken());	m_Elements = new double [rows][cols];	initialize();	currentRow ++;	continue;      } else {	if (currentRow == numRows()) {	  throw new Exception("Line " + lnr.getLineNumber() 			      + ": too many rows provided");	}	for (int i = 0; i < numColumns(); i++) {	  if (!st.hasMoreTokens()) {	    throw new Exception("Line " + lnr.getLineNumber() 				+ ": too few matrix elements provided");	  }	  m_Elements[currentRow][i] = Double.valueOf(st.nextToken())	    .doubleValue();	}	currentRow ++;      }    }    if (currentRow == -1) {      throw new Exception("Line " + lnr.getLineNumber() 			      + ": expected number of rows");    } else if (currentRow != numRows()) {      throw new Exception("Line " + lnr.getLineNumber() 			  + ": too few rows provided");    }  }