0% found this document useful (0 votes)
8 views3 pages

Java Matrix Operations Example

The document contains a Java program that creates a square matrix of size N, fills it with random integers, and sorts the diagonal elements in ascending order. It includes two classes: Matrices, which handles user input and matrix operations, and Operaciones, which contains methods for loading, displaying, and sorting the matrix. The program demonstrates its functionality by outputting the original and sorted matrices.

Uploaded by

jeff yupanqui
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Java Matrix Operations Example

The document contains a Java program that creates a square matrix of size N, fills it with random integers, and sorts the diagonal elements in ascending order. It includes two classes: Matrices, which handles user input and matrix operations, and Operaciones, which contains methods for loading, displaying, and sorting the matrix. The program demonstrates its functionality by outputting the original and sorted matrices.

Uploaded by

jeff yupanqui
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

package PracticaMatrices;

import [Link];

public class Matrices {

public static void main(String [] args){

Scanner leer = new Scanner([Link]);

int matriz[][] ;

[Link]("ORDEN: ");

int N = [Link]();

matriz = new int[N][N];

Operaciones obj = new Operaciones();

obj.cargar_matriz(matriz);

obj.visualizar_matriz(matriz);

obj.ordenar_diagonal(matriz, N);

obj.visualizar_matriz(matriz);

package PracticaMatrices;
public class Operaciones {

void cargar_matriz(int matriz[][]){

for(int i=0; i<[Link]; i++){

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

matriz[i][j] = (int) ([Link]()*10+1);

void visualizar_matriz(int matriz[][]){

[Link]("MATRIZ:");

for(int i=0; i<[Link] ;i++){

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

[Link](matriz[i][j]+"\t");

[Link]("");

void ordenar_diagonal(int matriz[][],int N){

int aux;

for(int i=0;i<N-1;i++){

for(int j=0; j<N-i-1; j++){

if(matriz[j][j]<matriz[j+1][j+1]){

aux = matriz[j][j];

matriz[j][j] = matriz[j+1][j+1];
matriz[j+1][j+1] = aux;

COMPILACION:

ORDEN: 4

MATRIZ:

2 10 4 4

1 10 3 3

4 9 5 2

10 10 10 3

MATRIZ:

10 10 4 4

1 5 3 3

4 9 3 2

10 10 10 2

BUILD SUCCESSFUL (total time: 2 seconds)

You might also like