Fig10_38 - for( int j = 0; j < n; j++ ) for( int...

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

View Full Document Right Arrow Icon
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++ )
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for( int j = 0; j &lt; n; j++ ) for( int k = 0; k &lt; 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 ] + &quot; &quot; + c[ 0 ][ 1 ] + &quot; &quot; + c[ 1 ][ 0 ] + &quot; &quot; + c[ 1 ][ 1 ] ); } }...
View Full Document

This document was uploaded on 06/13/2011.

Ask a homework question - tutors are online