// purpose: demonstrate default matrix initialization public class MatrixDefault { public static void main( String[] args ) { int[][] a = new int[ 4 ][ 4 ]; int rows = a.length; int columns = a[0].length; System.out.println( "a before manipulation" ); System.out.println( "_______________________" ); for ( int r = 0; r < rows; ++r ) { // process row r for ( int c = 0; c < columns; ++c ) { // process the element in column c of row r System.out.print( a[ r ][ c ] + " " ); } System.out.println(); } System.out.println(); System.out.println(); for ( int r = 0; r < rows; ++r ) { // process row r for ( int c = 0; c < columns; ++c ) { // process the element in column c of row r a[ r ][ c ] = r + c; } } System.out.println( "a after manipulation" ); System.out.println( "_______________________" ); for ( int r = 0; r < rows; ++r ) { // process row r for ( int c = 0; c < columns; ++c ) { // process the element in column c of row r System.out.print( a[ r ][ c ] + " " ); } System.out.println(); } } }