/** @(#)RestaBordes.java 2013 adolfo@di-mare.com Programa que la resta de matrices. http://www.di-mare.com/adolfo/cursos/2009-2/pi-ea-f.htm#Mx.Borde.Resta%28%29 @author Adolfo Di Mare */ /** Clase que contiene el programa principal {@code main()}. */ public class RestaBordes { /* Calcula y retorna la resta A-B. * Usa la regla definida en: * http://www.di-mare.com/adolfo/cursos/2009-2/pi-ea-f.htm#Mx.Borde.Resta%28%29 */ public static int [][] restador( int A [][], int B [][] ) { /* *** RELLENE CON SU ALGORITMO *** */ int RESTA [][] = new int [A.length][B[0].length]; return RESTA; } static int V_456[][] = new int[][] { { 456, 554, 941, 942 }, { 478, 240, 404, 499 }, { 941, 992, 224, 786 }, { 348, 743, 598, 210 } }; static int V_456_cero[][] = new int[][] { { 0, 0, 0, 0 }, { 0, 240, 404, 0 }, { 0, 992, 224, 0 }, { 0, 0, 0, 0 }, }; static int W_222[][] = new int[][] { { 222, 222, 222, 222 }, { 111, 111, 111, 111 }, { 222, 222, 222, 222 }, { 111, 111, 111, 111 } }; /** Programa principal. */ public static void main( String args[] ) { imprima( V_456, V_456_cero, restador(V_456,V_456_cero) , 4 ); System.out.print( "\n\n" ); imprima( W_222, W_222, restador(W_222,W_222) , 4 ); } /** Graba las 3 matrices, una B la par de la otra. */ private static void imprima( int A[][] , int B[][] , int C[][] , int w ) { if ( (A.length!=B.length) || (B.length!= C.length) ) { System.out.println( "NO se vale usar matrices de tamaņo diferente" ); return; } int DIM = A.length; for ( int i=0; i |" ); for ( int j=0 ; j=0); if (!esPositivo) { n = -n; } String res = ""; do { w--; int digito = n%10; n /= 10; res = (char)(digito+'0') + res; } while (n!=0); if (!esPositivo) { res = "-" + res; w--; } // pone el signo while ( w>0 ) { res = " " + res; w--; } return res; } }