import java.util.Arrays; public class ScalarMult { public static void main() { double [][] a = { {1, 8, -3}, {4, -2, 5} }; double[][] b; b = scalarMultiply(a, 2); System.out.println( Arrays.toString(a[0]) ); System.out.println( Arrays.toString(a[1]) ); System.out.println( " * " + 2 + " = " ); System.out.println( Arrays.toString(b[0]) ); System.out.println( Arrays.toString(b[1]) ); } public static double[][] scalarMultiply(double[][] m, double a) { double[][] result = new double[m.length][m[0].length]; // result matrix has // same # rows and # columns as m for (int i = 0; i < m.length; i++) { for (int j = 0; j < m[0].length; j++) { result[i][j] = m[i][j] * a; } } return result; } }