Question about matrix in java

0

I need to do this exercise Perform a Program that allows filling a square matrix of NxN and obtaining the following values:

1) Main and secondary diagonal

2) Sum of elements in each row

3) Value of an element in position X (row) and Y (column)

4) Maximum element per row

5) Percentage of Negative Values per Column

The thing is that to do it I need the matrix to be n x n in java, and I can not do it. So far I am trying to make the matrix n x n where the user enters the size and also enter the values for X and Y

I have this

package prueba2;

import java.util.Scanner;
import javax.swing.JOptionPane;

/**
 *
 * @author _Victor_
 */
public class Prueba2 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner entrada = new Scanner(System.in);
        int nelementosx = 0;
        int nelementosy = 0;

       nelementosx = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el tamaño para X"));
       nelementosy = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el tamaño para Y"));

       int [][] matriz = new int [nelementosx][nelementosy];
        // Hasta aqui esta el tamaño de la matriz nxn

        // Ingresar elementos

          System.out.println("Elija los numreos del arreglo");
           for (int i = 0; i < nelementosx; i++){
         System.out.println(" ");
         for (int j = 0; j < nelementosy; j++){
             System.out.println("-Digite un numero para X ");
         matriz[i] = entrada.nextInt();
             System.out.println("-Digite un numero para Y ");
         matriz[j] = entrada.nextInt();

           }

         }
    }
}
    
asked by Victor Escalona 06.03.2018 в 04:09
source

0 answers