my code stock.com

Implementar la función “mayorX_Y”, que recibe una matriz, y es verdadera cuando:
todas las filas Xi son mayores que alguna columna Yi
Una fila es mayor que una columna cuando la suma de sus números es mayor.
Por ejemplo, sea la matriz m:
{10,20,30},{10,20,30},{10,20,30}

Snippet options

Download: Download snippet as mayorx_y.java.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

public class Ej4Bis {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Integer m[][]= {{10,10,10},{10,1,2},{3,4,4},{3,4,4}};
		System.out.println(mayorX_Y(m));	
	}
	
 static boolean mayorX_Y(Integer [][] matriz){

	int sumF= 0;
	int sumC=0;
	
	boolean cond1=false;
	boolean ret = true;
	
	
	for(int x=0; x< matriz.length;x++){//Recorre filas
		for(int y=0; y< matriz[0].length; y++){
			sumF = sumF + matriz[x][y];	
		}//al salir de este for sumF contiene la suma de la fila actual
		for (int i =0;i<matriz[0].length;i++){//al salir de este for sumaCol contiene la suma de la columna
			sumC= sumaCol(matriz,i);
			//System.out.println("con: " + sumC);
			cond1=cond1 || sumF>sumC;
			sumC=0;
			}//sale de la columna
        ret = ret && cond1;
		cond1=false;
		sumF=0;
	}
 	return ret;
	}
		
 
 static int sumaCol(Integer[][] matriz, int col){// devuelve la suma de una columna
int suma=0;		
for (int fila=0;fila<matriz[0].length;fila++){
	 suma = suma + matriz[fila][col];// col es un valor fijo
	}
return suma;	
	}
}

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.