0% found this document useful (0 votes)
11 views

Matrices Java

matrices bidimensional

Uploaded by

jeff yupanqui
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Matrices Java

matrices bidimensional

Uploaded by

jeff yupanqui
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

package PracticaMatrices;

import java.util.Scanner;

/**

* @author YUPANQUI CASTELLANOS

*/

public class Matrices {

public static void main(String [] args){

Scanner leer = new Scanner(System.in);

int matriz[][];

int filas;

int columnas;

System.out.print("FILAS: ");

filas = leer.nextInt();

System.out.print("COLUMNAS: ");

columnas = leer.nextInt();

System.out.println("");

matriz = new int[filas][columnas];

Operaciones obj = new Operaciones();

obj.leer_matriz(matriz);

obj.visualizar_matriz(matriz);

obj.sumar_diagonales(matriz, filas, columnas);

}
}

package PracticaMatrices;

/**

* @author YUPANQUI CASTELLANOS

*/

public class Operaciones {

void leer_matriz(int [][] matriz){

for(int i=0; i<matriz.length; i++){

for(int j=0; j<matriz[0].length; j++){

matriz[i][j] = (int) (Math.random()*10+1);

void visualizar_matriz(int [][] matriz){

for(int i=0; i<matriz.length; i++){

for(int j=0; j<matriz[0].length; j++){

System.out.print(matriz[i][j]+"\t");

System.out.println("");

}
}

void sumar_diagonales(int [][] matriz, int filas, int columnas){

int suma_prin = 0;

int suma_sec = 0;

int suma_diag;

if(filas == columnas){

for(int i=0; i<matriz.length; i++){

suma_prin += matriz[i][i];

for(int i=0; i<matriz.length; i++){

suma_sec += matriz[i][matriz.length-i-1];

suma_diag = suma_prin +suma_sec;

System.out.println("");

System.out.println("SUMA DIAGONALES: "+ suma_diag);

else{

System.out.println("LA MATRIZ NO ES CUADRADA");

}
COMPILACION:

run:

FILAS: 3

COLUMNAS: 3

4 1 6

8 3 9

7 6 8

SUMA DIAGONALES: 31

BUILD SUCCESSFUL (total time: 4 seconds)

You might also like