Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created January 7, 2020 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/04d80b63dd1acc7d70b36595b29f96fb to your computer and use it in GitHub Desktop.
Save parzibyte/04d80b63dd1acc7d70b36595b29f96fb to your computer and use it in GitHub Desktop.
class Main {
public static void main(String[] args) {
int arreglo[] = { 1, 3, 4, 90, 92 };
// Para obtener la suma recorremos el arreglo y sumamos cada valor
int suma = 0;
for (int x = 0; x < arreglo.length; x++) {
suma = suma + arreglo[x];
}
// El promedio es la suma dividida entre la cantidad de elementos
float promedio = suma / arreglo.length;
System.out.printf("Suma: %d. Promedio: %f", suma, promedio);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment