Created
September 18, 2019 16:08
-
-
Save parzibyte/45950ac565aa113a59cf8336a44cba60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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