Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created Feb 11, 2020
Embed
What would you like to do?
/*
Programado por Luis Cabrera Benito
____ _____ _ _ _
| _ \ | __ \ (_) | | |
| |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
| _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
| |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
|____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
__/ | __/ |
|___/ |___/
Blog: https://parzibyte.me/blog
Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
Contacto: https://parzibyte.me/blog/contacto/
*/
class Main {
public static void main(String[] args) {
int[][] matriz = { { 11, 1232, 386, 432 }, { 47, 454, 254, 353 } };
int sumatoria = 0; // Aquí iremos sumando cada valor
int cantidadDeElementos = 0; // Contar los elementos
// Recorremos la matriz
for (int x = 0; x < matriz.length; x++) {
for (int y = 0; y < matriz[x].length; y++) {
int numeroActual = matriz[x][y];
sumatoria = sumatoria + numeroActual;
cantidadDeElementos = cantidadDeElementos + 1;
}
}
float promedio = (float) sumatoria / cantidadDeElementos;
System.out.printf("La sumatoria es %d y el promedio es %f", sumatoria, promedio);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment