Matrix 10 * 10 print cross-stitch and print which is the smallest

0

How do I make the route to print the smaller number of the crusade print?

package mp4;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Mp4 {

    public static void main(String[] args) throws IOException {
        BufferedReader bufEntrada = new BufferedReader(new InputStreamReader(System.in));
        double a;
        double b;
        int i;
        int j;
        String m[][];
        String opc;
        String vd[];
        m = new String[50][50];
        vd = new String[10];
        do {

            System.out.println("INGRESE CANTIDAD DE FILAS Y COLUMNAS DE LA MATRIZ");
            System.out.println("NO. DE FILAS:");
            a = Double.parseDouble(bufEntrada.readLine());
            System.out.println("NO. DE COLUMNAS:");
            b = Double.parseDouble(bufEntrada.readLine());
            if (a==b) {
                System.out.println("INGRESE DATOS DE LA MATRIZ");

                System.out.println("");
                for (i=1;i<=a;i++) {
                    for (j=1;j<=b;j++) {
                        System.out.println("INGRESE DATO DE LA POSICION "+i+","+j);
                        m[i-1][j-1] = bufEntrada.readLine();

                        if (j==i) {
                            vd[i-1] = m[i-1][j-1];
                        }
                    }
                }

                for (j=1;j<=a;j++) {
                    for (i=1;i<=b;i++) {
                        System.out.print(m[i-1][j-1]+" ");
                    }
                    System.out.println("");
                }
                System.out.println("");
                System.out.println("LOS ELEMENTOS ALMACENADOS EN EL VECTOR SON:");
                for (i=1;i<=a;i++) {
                    System.out.println(vd[i-1]);


                                }
                                  int menor;
         System.out.println("EL ELEMENTO MENOR DE LA MATRIZ DE CRUZADA:"); 

                        }


                        else {
                System.out.println(" ERROR");
                System.out.println("LO SENTIMOS LA MATRIZ NO ES PROPORCIONAL");
                System.out.println(" PRESIONE TECLA PARA CONTINUAR");
            }
            System.in.read(); 
            System.out.println(""); 
            System.out.println("USAR NUEVAMENTE");
            opc = bufEntrada.readLine();
        } while (!(opc.equals("NO") || opc.equals("no")));
    }
}
    
asked by ANDRES FELIPE CASTILLA RAMIREZ 25.09.2018 в 09:28
source

2 answers

0

Whereas the vector with the values of the cross matrix is vd[i-1] . find the smallest can be done in the following way:

int menor = vd[0]  //Esto es para que considere el primer valor como el menor.
for (i=2;i<=a;i++){
 if(vd[i-1]<menor){
    menor = vd[i-1];   //compara el menor en cada recorrido del array.
 }
}

The variable menor would be the answer.

Luck

    
answered by 25.09.2018 в 09:39
0
public static void main(String[] args) throws IOException {
    BufferedReader bufEntrada = new BufferedReader(new InputStreamReader(System.in));
    double a;
    double b;
    int i;
    int j;
    String m[][];
    String opc;
    String vd[];
    m = new String[50][50];
    vd = new String[10];
    do {

        System.out.println("INGRESE CANTIDAD DE FILAS Y COLUMNAS DE LA MATRIZ");
        System.out.println("NO. DE FILAS:");
        a = Double.parseDouble(bufEntrada.readLine());
        System.out.println("NO. DE COLUMNAS:");
        b = Double.parseDouble(bufEntrada.readLine());
        if (a==b) {
            System.out.println("INGRESE DATOS DE LA MATRIZ");

            System.out.println("");
            for (i=1;i<=a;i++) {
                for (j=1;j<=b;j++) {
                    System.out.println("INGRESE DATO DE LA POSICION "+i+","+j);
                    m[i-1][j-1] = bufEntrada.readLine();

                    if (j==i) {
                        vd[i-1] = m[i-1][j-1];
                    }
                }
            }

            for (j=1;j<=a;j++) {
                for (i=1;i<=b;i++) {
                    System.out.print(m[i-1][j-1]+" ");
                }
                System.out.println("");
            }
            System.out.println("");
            System.out.println("LOS ELEMENTOS ALMACENADOS EN EL VECTOR SON:");
            for (i=1;i<=a;i++) {
                System.out.println(vd[i-1]);


                            }
                              int menor = vd[0]
      for (i=2;i<=a;i++){
       if(vd[i-1]<menor){
        menor = vd[i-1];  
       }
      }
     System.out.println("EL ELEMENTO MENOR DE LA MATRIZ DE CRUZADA:"+menor); 

                    }


                    else {
            System.out.println(" ERROR");
            System.out.println("LO SENTIMOS LA MATRIZ NO ES PROPORCIONAL");
            System.out.println(" PRESIONE TECLA PARA CONTINUAR");
        }
        System.in.read(); 
        System.out.println(""); 
        System.out.println("USAR NUEVAMENTE");
        opc = bufEntrada.readLine();
    } while (!(opc.equals("NO") || opc.equals("no")));
}
    
answered by 25.09.2018 в 10:14