Desarrollo de Software en C++, C#, PHP,JavaScript, Matlab, Java, Android, Arduino, Python, Flutter, React, Vue, Solución de ejercicios, Programas informáticos, Inteligencia Artificial.

Buscar

Máximo y Mínimo de dos Matrices en java

import java.util.Scanner;
public class algoritmo_10_matriz {
    Scanner leer= new Scanner (System.in);
   
 
    public static void main(String[] args){
       algoritmo_10_matriz menu= new algoritmo_10_matriz();
       menu.menuGeneral();
    }
 
   public int menuGeneral(){
   int opcion;
   do{
       System.out.println("");
       System.out.println("===================================================");
       System.out.println("================= MENU DE OPCIONES ================");
       System.out.println("===== 1.SUMA DE MATRICES                       ====");
       System.out.println("===== 2.MULTIPLICACION DE MATRICES             ====");
       System.out.println("===== 3.TRANSPUESTA MATRIZ A^B                 ====");
       System.out.println("===== 4.SUMA DIAGONAL PRINCIPAL MATRIZ A^B     ====");
       System.out.println("===== 5.MAXIMO Y MINIMO MATRIZ A ^ B           ====");
       System.out.println("===== 6.COLUMNA IMPAR ^ FILAS PARES MATRIZ A^B ====");
       System.out.println("===== 7.SALIR                                  ====");
       System.out.println("===================================================");
       System.out.print("Ingrese una opcion: ");
       opcion=leer.nextInt();
 
       switch(opcion){
           case 1: SumadeMatriz(); break;
           case 2: MultiplicacionMatriz();break;
           case 3: TranspuestaMatriz();break;
           case 4: DiagonalPrincipalMatrices();break;
           case 5: MaximoMinimoMatriz();break;
           case 6: ColumnaImparFilaPar();break;
           case 7: System.out.println("................Saliendo del menu ..............");
               System.exit(0); break;
           default: System.out.println("Ingrese una opcion valida.......!!"); break;

       }
     
     
     
   }while(opcion != 8);
   return 0;
   }

public void MaximoMinimoMatriz(){

        int n, m, i, j;
        int A[][] = new int[10][10];
        int B[][] = new int[10][10];
     
        System.out.print("Ingrese dimension n: ");
        n = leer.nextInt();
        System.out.print("Ingrese dimension m: ");
        m = leer.nextInt();

        System.out.println("INGRESE VALORES MATRIZ A");
        for (i = 1; i <= n; i++) {
            for (j = 1; j <= m; j++) {
                System.out.print("A[" + (i) + "," + (j) + "]= ");
                A[i][j] = leer.nextInt();
            }
        }

        System.out.println("INGRESE VALORES MATRIZ B");
        for (i = 1; i <= n; i++) {
            for (j = 1; j <= m; j++) {
                System.out.print("B[" + (i) + "," + (j) + "]= ");
                B[i][j] = leer.nextInt();
            }
        }

        //IMPRIMIENDO MATRICES A Y B
        System.out.println("======== MATRIZ A =========");
        for (i = 1; i <= n; i++) {
            for (j = 1; j <= m; j++) {
                System.out.print("\t" + A[i][j]);
            }
            System.out.println();
        }

        System.out.println("====== MATRIZ B ========");
        for (i = 1; i <= n; i++) {
            for (j = 1; j <= m; j++) {
                System.out.print("\t" + B[i][j]);
            }
            System.out.println();
        }
     
       int menorA=A[1][1],mayorA=A[1][1],menorB=B[1][1],mayorB=B[1][1];
     
        System.out.println("*********************  MATRIZ A (MAXIMO Y MINIMO) ***************");
        for (i = 1; i <= n; i++) {
            for (j = 1; j <= m; j++) {
                //calculo del MENOR valor de la matriz
                if(i!=1 && j!=1){
                 if(A[i][j]>mayorA){
                    mayorA=A[i][j];
                }
                //calculo del MAYOR valor de la matriz
                if(A[i][j]<menorA){
                    menorA=A[i][j];
                }
                }
            }
        }
     
        System.out.println("NUMERO MENOR DE MATRIZ : "+menorA);
        System.out.println("NUMERO MAYOR DE MATRIZ : "+mayorA);
     
        System.out.println("*********************  MATRIZ B (MAXIMO Y MINIMO) ****************");
        for (i = 1; i <= n; i++) {
            for (j = 1; j <= m; j++) {
                //calculo del mayor valor de la matriz
                if(i!=1 && j!=1){
                 if(B[i][j]>mayorB){
                    mayorB=B[i][j];
                }
                //calculo del menor valor de la matriz
                if(B[i][j]<menorB){
                    menorB=B[i][j];
                }
                }
            }
        }

        System.out.println("NUMERO MENOR DE MATRIZ : "+menorB);
        System.out.println("NUMERO MENOR DE MATRIZ :"+mayorB);

}

}
Share:

0 comments:

Publicar un comentario

DISCULPA LAS MOLESTIAS, LA PUBLICIDAD NOS AYUDA

Para descargar Aguarda 5 seg. y luego hacer click en saltar publicidad...Gracias !!

Saltar Publicidad

Translate

FACEBOOK

Ayúdanos con tu donación !

Etiquetas

twitter.com

Páginas vistas

Labels