package javahomework; public class HW08 { public static void main(String arg[]) { int a[][] = new int[2][2]; int b[][] = new int[2][2]; int c[][] = new int[2][2]; for (int i = 0; i < a.length; i++) for (int j = 0; j < a[i].length; j++) a[i][j] = (int) (Math.random() * 10); for (int i = 0; i < b.length; i++) for (int j = 0; j < b[i].length; j++) b[i][j] = (int) (Math.random() * 10); for (int i = 0; i < a.length; i++) for (int j = 0; j < b[i].length; j++) for (int k = 0; k < b[j].length; k++) c[i][j] = c[i][j] + a[i][k] * b[k][j]; for (int i = 0; i < c.length; i++) { for (int j = 0; j < c[i].length; j++) System.out.print(c[i][j] + " "); System.out.print("\n"); } } }
2008年8月29日 星期五
利用亂數產生兩個二維陣列A,B計算出C=A*B
code
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言