Vous êtes sur la page 1sur 4

public int promedioNumerosPares() {

int suma = 0;
int contador = 0;
for (int i = 0; i <= getFilas() - 1; i++) {
for (int j = 0; j <= getColumnas() - 1; j++) {
if (getMatriz(i, j) % 2 == 0) {
contador ++;
suma = suma + getMatriz(i, j);
}

}
}
return (suma / contador);
}

public int sumaMatriz(){


int suma=0;
for (int i = 0; i <=getFilas()-1; i++) {
for (int j = 0; j <=getColumnas()-1; j++) {
suma=suma+getMatrizNumeros(i,j);
}
}
return suma;
}

public int sumaDiagonalprincipal(){


int suma=0;
for (int i = 0; i <=getFilas()-1; i++) {
for (int j = 0; j <=getColumnas()-1; j++) {
if(i==j){
suma=suma+getMatrizNumeros(i,j);
}
}
}
return suma;
}

public int segundaDiagonal(){


int suma=0;
for (int i = 0; i <=getFilas()-1; i++) {
for (int j = 0; j <=getColumnas()-1; j++) {
if (i+j==getColumnas()-1) {
suma=suma+getMatrizNumeros(i,j);

}
}
return suma;
}

public double promedioMatriz(){


double suma=0;
for (int i = 0; i <=getFilas()-1; i++) {
for (int j = 0; j <=getColumnas()-1; j++) {
suma=suma+getMatrizNumeros(i,j);

}
}

return suma/(getColumnas()*getFilas());
}

public int sumaBorde(){


int suma=0;
for (int i = 0; i <=getFilas()-1; i++) {
for (int j = 0; j <=getColumnas()-1; j++) {
if (i==0||j==0||i==getColumnas()-1||j==getFilas()-1){
suma=suma+getMatrizNumeros(i,j);
}

}
return suma;
}
}

public static void mostrarDiagonalPrincipal(DeclararMatriz obj){


String datosMatriz="";
for(int i=0; i<=obj.getFilas()-1; i++){
for(int j=0; j<=obj.getColumnas()-1; j++){
if(i == j){
datosMatriz = datosMatriz+String.valueOf(obj.getMatrizNumeros(i,j)+" ");
}
else{
datosMatriz = datosMatriz+String.valueOf("--");
}
}
datosMatriz = datosMatriz+"\n"+"\n";
}
JOptionPane.showMessageDialog(null, "===== DATOS DE LA MATRIZ
====="+"\n"+datosMatriz);
}

public static void mostrarSegundaDiagonal(DeclararMatriz obj){


String datosMatriz="";
for (int i = 0; i <=obj.getFilas()-1; i++) {
for (int j = 0; j <=obj.getColumnas()-1; j++) {
if (i+j==obj.getFilas()-1){
datosMatriz=datosMatriz+String.valueOf(obj.getMatrizNumeros(i,j)+" ");
}else{
datosMatriz = datosMatriz+String.valueOf("--");
}
}
datosMatriz=datosMatriz+"\n"+"\n";
}
JOptionPane.showMessageDialog(null, "===== DATOS DE LA MATRIZ
====="+"\n"+datosMatriz);
}

public static void mostrarBordeMatriz(DeclararMatriz obj){


String datosMatriz="";
for(int i=0; i<=obj.getFilas()-1; i++){
for(int j=0; j<=obj.getColumnas()-1; j++){
if (i==0||j==0||i==obj.getFilas()-1||j==obj.getColumnas()-1) {
datosMatriz=datosMatriz+String.valueOf(obj.getMatrizNumeros(i,j)+" ");
}
else{
datosMatriz = datosMatriz+String.valueOf("-- ");
}
}
datosMatriz = datosMatriz+"\n"+"\n";
}
JOptionPane.showMessageDialog(null, "===== DATOS DE LA MATRIZ
====="+"\n"+datosMatriz);
}

public static void mostrarTranspuesta(DeclararMatriz obj){


String datosMatriz="";
for(int i=0; i<=obj.getFilas()-1; i++){
for(int j=0; j<=obj.getColumnas()-1; j++){
datosMatriz = datosMatriz+String.valueOf(obj.getMatrizNumeros(j,i)+" ");
}
datosMatriz = datosMatriz+"\n"+"\n";
}
JOptionPane.showMessageDialog(null, "======== DATOS DE LA MATRIZ
======="+"\n"+datosMatriz);
}

Vous aimerez peut-être aussi