1. Dadas dos matrices A y B intercambiar los minimos de A con los maximos de B
    import java.util.Scanner;
    
    public class JavaMatrizMetod1 {
      
      Scanner Leer = new Scanner(System.in);
      
      public static void llenar (int M [] [], int f, int c)
      {
          Scanner Leer = new Scanner(System.in);
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    for (int j = 1 ; j <= c ; j++)
    	    {
    		System.out.print ("Inserte pos[" + i + "][" + j + "]: ");
    		M [i] [j] = Leer.nextInt();
    	    }
    	}
        }
        public static void mostrar (int M [] [], int f, int c)
        {
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    System.out.println ();
    	    for (int j = 1 ; j <= c ; j++)
    	    {
    		System.out.print ("[" + M [i] [j] + "]");
    	    }
    	}
        }
        public static int menor (int M [] [], int f, int c)
        {
    	int men = M [1] [1];
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    for (int j = 1 ; j <= c ; j++)
    	    {
    		if (M [i] [j] < men)
    		    men = M [i] [j];
    	    }
    	}
    	return (men);
        }
        public static int maximo (int M [] [], int f, int c)
        {
    	int max = M [1] [1];
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    for (int j = 1 ; j <= c ; j++)
    	    {
    		if (M [i] [j] < max)
    		    max = M [i] [j];
    	    }
    	}
    	return (max);
        }
        public static void intercambiar (int A [] [], int fa, int ca, int B [] [], int fb, int cb)
        {
    	int min_a = menor (A, fa, ca);
    	int max_b = maximo (B, fb, cb);
    
    	//para cambiar los minimos de A con los maximos de B
    	for (int i = 1 ; i <= fa ; i++)
    	{
    	    for (int j = 1 ; j <= ca ; j++)
    	    {
    		if (A [i] [j] == min_a)
    		    A [i] [j] = max_b;
    	    }
    	}
    
    	//para intercambiar los maximos de con los minimos de A
    	for (int i = 1 ; i <= fb ; i++)
    	{
    	    for (int j = 1 ; j <= cb ; j++)
    	    {
    		if (B [i] [j] == max_b)
    		    B [i] [j] = min_a;
    	    }
    	}
        }
        public static void main (String args [])
        {
            Scanner Leer = new Scanner(System.in);
    	int A [] [] = new int [20] [20];
    	int B [] [] = new int [20] [20];
    	System.out.print ("Insert filas de A: ");
    	int fa = Leer.nextInt();
    	System.out.print ("Insert columnas de A: ");
    	int ca = Leer.nextInt();
    	System.out.print ("Insert filas de B: ");
    	int fb = Leer.nextInt();
    	System.out.print ("Insert columnas de B: ");
    	int cb = Leer.nextInt();
    
    	//lectura de matrices
    	System.out.println ("nINSERTANDO DATOS EN MATRIZ A: n");
    	llenar (A, fa, ca);
    	System.out.println ("nINSERTANDO DATOS EN MATRIZ B: n");
    	llenar (B, fb, cb);
    	System.out.println ("nMATRICES ORIGINALMENTE INSERTADAS: ");
    	mostrar (A, fa, ca);
    	System.out.println ();
    	mostrar (B, fb, cb);
    	System.out.println ();
    
    	//intercambiando elementos
    	intercambiar (A, fa, ca, B, fb, cb);
    	System.out.println ("nMATRICES DESPUES DEL INTERCAMBIO:");
    	mostrar (A, fa, ca);
    	System.out.println ();
    	mostrar (B, fb, cb);
        } 
    }
    
  2. Dada una matriz cuadrada invertir su diagonal principal
    import java.util.Scanner;
    
    public class JavaMatrizMetod2 {
        
      public static void llenar (int M [] [], int d)
        {
            Scanner Leer = new Scanner(System.in);
    	for (int i = 1 ; i <= d ; i++)
    	{
    	    for (int j = 1 ; j <= d ; j++)
    	    {
    		System.out.print("Inserte pos[" + i + "][" + j + "]: ");
    		M [i] [j] = Leer.nextInt();
    	    }
    	}
        }
        public static void mostrar (int M [] [], int d)
        {
    	for (int i = 1 ; i <= d ; i++)
    	{
    	    System.out.println ();
    	    for (int j = 1 ; j <= d ; j++)
    	    {
    		System.out.print("[" + M [i] [j] + "]");
    	    }
    	}
        }
        public static void invierte (int M [] [], int d)
        {
    	int fin = d;
    	for (int i = 1 ; i <= d / 2 ; i++)
    	{
    	    int aux = M [i] [i];
    	    M [i] [i] = M [d] [d];
    	    M [d] [d] = aux;
    	    fin--;
    	}
        }
        public static void main (String args [])
        {
            Scanner Leer = new Scanner(System.in);
    	int M [] [] = new int [20] [20];
    	System.out.print("Inserte dimen. de la matriz cuadrada: ");
    	int d = Leer.nextInt();
    	llenar (M, d);
    	System.out.print("nMATRIZ ORIGINAL: ");
    	mostrar (M, d);
    	System.out.print("nnMATRIZ CON LA DIAGONAL PRINCIPAL INVERTIDA: ");
    	invierte (M, d);
    	mostrar (M, d);
        }
      
    }
    
  3. Dada una matriz cuadrada invertir su diagonal secundaria
    import java.util.Scanner;
    
    public class JavaMatrizMetod3 {
        
        public static void llenar (int M [] [], int d)
        {
            Scanner Leer = new Scanner(System.in);
    	for (int i = 1 ; i <= d ; i++)
    	{
    	    for (int j = 1 ; j <= d ; j++)
    	    {
    		System.out.print ("Inserte pos[" + i + "][" + j + "]: ");
    		M [i] [j] = Leer.nextInt();
    	    }
    	}
        }
        public static void mostrar (int M [] [], int d)
        {
    	for (int i = 1 ; i <= d ; i++)
    	{
    	    System.out.println ();
    	    for (int j = 1 ; j <= d ; j++)
    	    {
    		System.out.print ("[" + M [i] [j] + "]");
    	    }
    	}
        }
        public static void invierte (int M [] [], int d)
        {
    	int fin = d;
    	for (int i = 1 ; i <= d / 2 ; i++)
    	{
    	    int aux = M [i] [d];
    	    M [i] [d] = M [d] [i];
    	    M [d] [i] = aux;
    	    fin--;
    	}
        }
        public static void main (String args [])
        {
            Scanner Leer = new Scanner(System.in);
    	int M [] [] = new int [20] [20];
    	System.out.print ("Inserte dimen. de la matriz cuadrada: ");
    	int d = Leer.nextInt();
    	llenar (M, d);
    	System.out.print ("nMATRIZ ORIGINAL: ");
    	mostrar (M, d);
    	System.out.print ("nnMATRIZ CON LA DIAGONAL SECUNDARIA INVERTIDA: ");
    	invierte (M, d);
    	mostrar (M, d);
        }
     
    }
    
  4. Dada dos matrices de diferentes tamaños R y S mostrar los elementos comunes de R en S
    import java.util.Scanner;
    
    public class JavaMatrizMetod4 {
        
        public static void llenar (int M [] [], int f, int c)
        {
            Scanner Leer = new Scanner(System.in);
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    for (int j = 1 ; j <= c ; j++)
    	    {
    		System.out.print ("Inserte pos[" + i + "][" + j + "]: ");
    		M [i] [j] = Leer.nextInt();
    	    }
    	}
        }
        public static void mostrar (int M [] [], int f, int c)
        {
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    System.out.println ();
    	    for (int j = 1 ; j <= c ; j++)
    	    {
    		System.out.print ("[" + M [i] [j] + "]");
    	    }
    	}
        }
        public static void comunes (int R [] [], int fr, int cr, int S [] [], int fs, int cs)
        {
    	System.out.print ("nnLos elementos comunes de R en S son: ");
    	for (int i = 1 ; i <= fr ; i++)
    	{
    	    for (int j = 1 ; j <= cr ; j++)
    	    {
    		for (int k = 1 ; k <= fs ; k++)
    		{
    		    for (int l = 1 ; l <= cs ; l++)
    		    {
    			if (R [i] [j] == S [k] [l])
    			    System.out.print ("[" + R [i] [j] + "]");
    		    }
    		}
    	    }
    	}
        }
        public static void main (String args [])
        {
            Scanner Leer = new Scanner(System.in);
    	int R [] [] = new int [20] [20];
    	int S [] [] = new int [20] [20];
    	System.out.print ("Inserte filas de R: ");
    	int fr = Leer.nextInt();
    	System.out.print ("Inserte columnas de R: ");
    	int cr = Leer.nextInt();
    	System.out.print ("Inserte filas de S: ");
    	int fs = Leer.nextInt();
    	System.out.print ("Inserte columnas de S: ");
    	int cs = Leer.nextInt();
    
    	System.out.print ("nLLENANDO MATRIZ R: n");
    	llenar (R, fr, cr);
    	System.out.print ("nLLENANDO MATRIZ S: n");
    	llenar (S, fs, cs);
    	System.out.print ("nLA MATRICES R : ");
    	mostrar (R, fr, cr);
    	System.out.print ("nLA MATRICES S : ");
    	mostrar (S, fs, cs);
    	comunes (R, fr, cr, S, fs, cs);
        }
    }
    
  5. Dada una matriz intercambiar los elementos de la primera columna con la ultima columna
    import java.util.Scanner;
    
    public class JavaMatrizMetod5 {
        
        public static void llenar (int M [] [], int f, int c)
        {
            Scanner Leer = new Scanner(System.in);
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    for (int j = 1 ; j <= c ; j++)
    	    {
    		System.out.print ("Inserte pos[" + i + "][" + j + "]: ");
    		M [i] [j] = Leer.nextInt();
    	    }
    	}
        }
        public static void mostrar (int M [] [], int f, int c)
        {
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    System.out.println ();
    	    for (int j = 1 ; j <= c ; j++)
    	    {
    		System.out.print ("[" + M [i] [j] + "]");
    	    }
    	}
        }
        public static void intercambiar (int M [] [], int f, int c)
        {
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    int aux = M [i] [1];
    	    M [i] [1] = M [i] 1;
    	    M [i] 1 = aux;
    	}
        }
        public static void main (String args [])
        {
            Scanner Leer = new Scanner(System.in);
    	int M [] [] = new int [20] [20];
    	System.out.print ("Inserte filas de la matriz: ");
    	int f = Leer.nextInt();
    	System.out.print ("Inserte columnas de la matriz: ");
    	int c = Leer.nextInt();
    
    	System.out.print ("nLLENANDO MATRIZ : n");
    	llenar (M, f, c);
    	System.out.print ("nLA MATRIZ ORIGINAL : ");
    	mostrar (M, f, c);
    	System.out.print ("nnLA MATRICES INTERCAMBIADA : ");
    	intercambiar (M, f, c);
    	mostrar (M, f, c);
        }
    }
    
  6. Contar el numero de digitos de cada elemento de una matriz
    import java.util.Scanner;
    
    public class JavaMatrizMetod6 {
        
        public static void llenar (int M [] [], int f, int c)
        {
            Scanner Leer = new Scanner(System.in);
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    for (int j = 1 ; j <= c ; j++)
    	    {
    		System.out.print ("Inserte pos[" + i + "][" + j + "]: ");
    		M [i] [j] = Leer.nextInt();
    	    }
    	}
        }
        public static void mostrar (int M [] [], int f, int c)
        {
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    System.out.println ();
    	    for (int j = 1 ; j <= c ; j++)
    	    {
    		System.out.print ("[" + M [i] [j] + "]");
    	    }
    	}
    
        }
        public static void cuenta (int M [] [], int f, int c)
        {
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    for (int j = 1 ; j <= c ; j++)
    	    {
    		System.out.print("n[" + M [i] [j] + "] tiene: " + digitos (M [i] [j]) + " digito(s)");
    	    }
    	}
        }
        public static int digitos (int n)
        {
    	int contador = 0;
    	while (n != 0)
    	{
    	    n = n / 10;
    	    contador++;
    	}
    	return (contador);
        }
        public static void main (String args [])
        {
            Scanner Leer = new Scanner(System.in);
    	int M [] [] = new int [20] [20];
    	System.out.print ("Inserte filas de la matriz: ");
    	int f = Leer.nextInt();
    	System.out.print ("Inserte columnas de la matriz: ");
    	int c = Leer.nextInt();
    
    	System.out.print ("nLLENANDO MATRIZ M: n");
    	llenar (M, f, c);
    	System.out.print ("nLA MATRIZ: ");
    	mostrar (M, f, c);
    	System.out.print ("nnCONTEO DE DIGITOS: ");
    	cuenta (M, f, c);
        }
    }
    
  7. Dada la matriz de m*n y el vector de tamaño n, determinar que columna de la matriz es igual al vector
    import java.util.Scanner;
    
    public class JavaMatrizVectorMetod1 {
       
        public static void llenarMatriz (int M [] [], int f, int c)
        {
            Scanner Leer = new Scanner(System.in);
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    for (int j = 1 ; j <= c ; j++)
    	    {
    		System.out.print ("Inserte pos[" + i + "][" + j + "]: ");
    		M [i] [j] = Leer.nextInt();
    	    }
    	}
        }
        public static void mostrarMatriz (int M [] [], int f, int c)
        {
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    System.out.println ();
    	    for (int j = 1 ; j <= c ; j++)
    	    {
    		System.out.print ("[" + M [i] [j] + "]");
    	    }
    	}
        }
        public static void llenarVector (int V [], int d)
        {
            Scanner Leer = new Scanner(System.in);
    	for (int i = 1 ; i <= d ; i++)
    	{
    	    System.out.print ("Inserte pos.[" + i + "]: ");
    	    V [i] = Leer.nextInt();
    	}
        }
        public static void mostrarVector (int V [], int d)
        {
    	for (int i = 1 ; i <= d ; i++)
    	{
    	    System.out.print ("[" + V [i] + "]");
    	}
        }
        public static void procedure (int M [] [], int f, int c, int V [], int d)
        {
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    int sw = 1;
    	    for (int j = 1 ; j <= c ; j++)
    	    {
    
    		for (int k = 1 ; k <= d ; k++)
    		{
    		    if (M [j] [i] != V [k])
    			sw = 0;
    		}
    	    }
    	    if (sw == 1)
    		System.out.println ("nnLa columna " + i + " es igual al vector");
    	}
        }
        public static void main (String args [])
        {
            Scanner Leer = new Scanner(System.in);
    	int M [] [] = new int [20] [20];
    	int V [] = new int [20];
    	System.out.print ("Inserte filas de la matriz: ");
    	int f = Leer.nextInt();
    	System.out.print ("Inserte dimension del vector: ");
    	int d = Leer.nextInt();
    
    	System.out.print ("nLLENANDO MATRIZ: n");
    	llenarMatriz(M, f, d);
    	System.out.print ("nLLENANDO EL VECTOR: n");
    	llenarVector (V, d);
    
    	System.out.print ("nLA MATRIZ: ");
    	mostrarMatriz(M, f, d);
    	System.out.print ("nnEL VECTOR: n");
    	mostrarVector (V, d);
    	procedure (M, f, d, V, d);
        } 
    }
    
  8. Dada una matriz Z almacenar en un vector A la suma por sus columnas y en un vector B la suma por sus filas
    import java.util.Scanner;
    
    public class JavaMatrizVectorMetod2 {
       
        public static void llenarMatriz (int M [] [], int f, int c)
        {
            Scanner Leer = new Scanner(System.in);
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    for (int j = 1 ; j <= c ; j++)
    	    {
    		System.out.print ("Inserte pos[" + i + "][" + j + "]: ");
    		M [i] [j] = Leer.nextInt();
    	    }
    	}
        }
        public static void mostrarMatriz (int M [] [], int f, int c)
        {
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    System.out.println ();
    	    for (int j = 1 ; j <= c ; j++)
    	    {
    		System.out.print ("[" + M [i] [j] + "]");
    	    }
    	}
        }
        public static void mostrarVector (int V [], int d)
        {
    	for (int i = 1 ; i <= d ; i++)
    	{
    	    System.out.print ("[" + V [i] + "]");
    	}
        }
        public static void vectorA (int M [] [], int f, int c, int A [], int d)
        {
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    int suma = 0;
    	    for (int j = 1 ; j <= c ; j++)
    	    {
    		suma = suma + M [j] [i];
    	    }
    	    A [i] = suma;
    	}
        }
        public static void vectorB (int M [] [], int f, int c, int B [], int d)
        {
    	for (int i = 1 ; i <= f ; i++)
    	{
    	    int suma = 0;
    	    for (int j = 1 ; j <= c ; j++)
    	    {
    		suma = suma + M [i] [j];
    	    }
    	    B [i] = suma;
    	}
        }
        public static void main (String args [])
        {
            Scanner Leer = new Scanner(System.in);
    	int Z [] [] = new int [20] [20];
    	int A [] = new int [20];
    	int B [] = new int [20];
    	System.out.print("Inserte filas de la matriz: ");
    	int f = Leer.nextInt();
    	System.out.print("Inserte columnas de la matriz: ");
    	int c = Leer.nextInt();
    
    	System.out.print("nLLENANDO MATRIZ: n");
    	llenarMatriz(Z, f, c);
    	System.out.print("nLA MATRIZ Z: ");
    	mostrarMatriz(Z, f, c);
    	System.out.println("nnSUMA POR COLUMNAS DE LA MATRIZ (vector A): ");
    	vectorA(Z, f, c, A, c);
    	mostrarVector (A, c);
    	System.out.println("nnSUMA POR FILAS DE LA MATRIZ (vector B): ");
    	vectorB(Z, f, c, B, f);
    	mostrarVector (B, f);
        } 
    }
    

Categorias: J2SE, JAVA

Leave a Reply


Oracle 11g R2 Sesion

CONEXION USANDO CON ORACLE SQL DEVELOPER Abrimos el sql Developer […]

Conectar C# con SQL

Conectar C# con SQL Server desde una cadena de conexion. […]

Insertar datos en un

Creamos una base de datos en MySQL. Creamos una tabla […]

Creación de Bases d

Creamos una base de datos llamada “prueba” en MySQL. Creamos […]

Conectar PHP con MyS

Conectar PHP con MySQL usando la función mysqli de PHP. […]

No public Twitter messages.

Sponsors

  • Cheap reliable web hosting from WebHostingHub.com.
  • Domain name search and availability check by PCNames.com.
  • Website and logo design contests at DesignContest.com.
  • Reviews of the best cheap web hosting providers at WebHostingRating.com.