# Fig10_38 - for int j = 0 j< n j for int k = 0 k< n k c...

This preview shows page 1. Sign up to view the full content.

public class Fig10_38 { /* START: Fig10_38.txt */ /** * Standard matrix multiplication. * Arrays start at 0. * Assumes a and b are square. */ public static int [ ][ ] multiply( int [ ][ ] a, int [ ][ ] b ) { int n = a.length; int [ ][ ] c = new int[ n ][ n ]; for( int i = 0; i < n; i++ ) // Initialization for( int j = 0; j < n; j++ ) c[ i ][ j ] = 0; for( int i = 0; i < n; i++ )
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for( int j = 0; j < n; j++ ) for( int k = 0; k < n; k++ ) c[ i ][ j ] += a[ i ][ k ] * b[ k ][ j ]; return c; } /* END */ / public static void main( String [ ] args ) { int [ ][ ] a = { { 1, 2 }, { 3, 4 } }; int [ ][ ] c = multiply( a, a ); System.out.println( c[ 0 ][ 0 ] + " " + c[ 0 ][ 1 ] + " " + c[ 1 ][ 0 ] + " " + c[ 1 ][ 1 ] ); } }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online