public class WriteMatrix2
1:
2: import java.io.*;
3:
4: public class WriteMatrix2 {
5:
6: static double[][] data = {
7: { Math.exp(2.0), Math.exp(3.0), Math.exp(4.0) },
8: { Math.exp(-2.0), Math.exp(-3.0), Math.exp(-4.0) },
9: };
10:
11: public static void main(String[] args) {
12: int row = data.length;
13: int col = data[0].length;
14: int i, j;
15: for (i = 0; i < row; i++) {
16: for (j = 0; j < col; j++) {
17: System.out.println("data[" + i + "][" + j + "] = " + data[i][j]);
18: }
19: }
20:
21: if (args.length > 0) {
22: try {
23: DataOutputStream out =
24: new DataOutputStream(new FileOutputStream(args[0]));
25: out.writeInt(row);
26: out.writeInt(col);
27: for (i = 0; i < row; i++) {
28: for (j = 0; j < col; j++) {
29: out.writeDouble(data[i][j]);
30: }
31: }
32: out.close();
33: } catch (IOException e) {}
34: }
35: }
36: }