matrix1 と matrix 2 という 2 つのテキスト ファイルがあります。これらのファイルには、4 行 4 列に積み上げられた数値が含まれています。を使用してそれを読み取って表示するにはどうすればよいJOptionPane
ですか? 問題はshowTable
私が信じている方法にあります。
public class MainApp {
private static final int ROW = 4;
private static final int COL = 4;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
double[][] m1 = new double[ROW][COL];
double[][] m2 = new double[ROW][COL];
double[][] m3 = new double[ROW][COL];
double[][] m4 = new double[COL][ROW];
m1 = LeerDatos("matrix1.txt");
showTable("Tabla 1", m1);
m2 = LeerDatos("matrix2.txt");
showTable("Tabla 2", m2);
m3 = sumarDatos(m1, m2);
showTable("m1 + m2: ", m3);
salvarTabla("suma.txt", m3);
m3 = restarTabla(m1,m2);
showTable("m1 - m2: ", m3);
salvarTabla("resta.txt", m3);
String numeroString = JOptionPane.showInputDialog("Escriba el numero escalar: ", "0.0");
double scalar = Double.parseDouble(numeroString);
m3 = scalarMultiplication( scalar, m2);
showTable("multiplicacion escalar con "
+ scalar , m3);
salvarTabla("scalar.txt", m3);
m4 = transpuesta(m1);
showTable("La transpuesta de tabla 1: ", m4);
salvarTabla("transpuesta.txt", m4);
System.exit(0);
}//main
private static void salvarTabla(String string, double[][] m4) {
}
private static double[][] transpuesta(double[][] m1) {
double[][] dummies = new double[m1.length][m1[0].length];
for (int row = 0; row < dummies.length; row++) {
for (int col = 0; col < dummies.length; col++) {
dummies[col][row] = m1[row][col];
}
}
return dummies;
}
private static double[][] scalarMultiplication(double scalar, double[][] m2) {
return null;
}
private static double[][] restarTabla(double[][] m1, double[][] m2) {
double dummies[][] = new double[m1.length][m1[0].length];
for (int row = 0; row < dummies.length; row++) {
for (int col = 0; col < dummies.length; col++) {
dummies[row][col] = m1[row][col] - m2[row][col];
}// for de col
}// for de row
return dummies;
}
private static double[][] sumarDatos(double[][] m1, double[][] m2) {
double dummies[][] = new double[m1.length][m1[0].length];
for (int row = 0; row < dummies.length; row++) {
for (int col = 0; col < dummies.length; col++) {
dummies[row][col] = m1[row][col] + m2[row][col];
}// for de col
}// for de row
return dummies;
}//sumar tabla
private static void showTable(String string, double[][] m1) {
// TODO Auto-generated method stub
double[][] dummies = new double[m1.length][m1[0].length];
for (int row = 0; row < dummies.length; row ++) {
for (int col = 0; col < dummies.length; col++) {
dummies[row][col] = m1[row][col];
JOptionPane.showMessageDialog(null, m1[row][col]);
}
}
}
private static double[][] LeerDatos(String filename) {
File file = new File(filename);
double dummies[][] = new double[ROW][COL];
try {
Scanner scanner = new Scanner ( new File (filename));
for (int row = 0; row < dummies.length; row++) {
for (int col = 0; col < dummies.length; col++) {
dummies[row][col] = scanner.nextDouble();
}
}// inner loop
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return dummies;
}
}