Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created September 18, 2019 16:08
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/45950ac565aa113a59cf8336a44cba60 to your computer and use it in GitHub Desktop.
Save parzibyte/45950ac565aa113a59cf8336a44cba60 to your computer and use it in GitHub Desktop.
// Elemento mayor de arreglo en Java
// https://parzibyte.me/blog
class Main {
public static void main(String[] args) {
int[] numeros = new int[] { 28, 50, 40, 200, 20, 44, 100, 153 };
// Asumir que el mayor es el primero
int mayor = numeros[0];
// Recorrer arreglo y ver si no es así
// (comenzar desde el 1 porque el 0 ya lo tenemos contemplado arriba)
for (int x = 1; x < numeros.length; x++) {
if (numeros[x] > mayor) {
mayor = numeros[x];
}
}
System.out.println("El mayor es: " + mayor);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment