Created
December 30, 2019 01:59
-
-
Save parzibyte/13c296acb7b9cf1410b3ed9a0786b9ff 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
/* | |
* Archivo: MayorMenorTresNumeros.java | |
* Clase: MayorMenorTresNumeros | |
* Autor: parzibyte | |
* Fecha: 12/29/19 7:45 PM | |
* Visita https://parzibyte.me/blog para más tutoriales sobre Java | |
*/ | |
public class MayorMenorTresNumeros { | |
public static void main(String[] args) { | |
int numeros[] = {2, 51, 33}; | |
int mayor = numeros[0];//Suponemos que el mayor es el primero | |
// Ciclo comienza en 1 porque el 0 ya está contemplado | |
for (int x = 1; x < numeros.length; x++) { | |
int numeroActual = numeros[x]; | |
if (numeroActual > mayor) { | |
mayor = numeroActual; | |
} | |
} | |
System.out.printf("Mayor: %d", mayor); | |
int otrosNumeros[] = {13, 12, 5, 12, 33, 1, 43}; | |
int menor = otrosNumeros[0];//Suponemos que el menor es el primero | |
// Ciclo comienza en 1 porque el 0 ya está contemplado | |
for (int x = 1; x < otrosNumeros.length; x++) { | |
int numeroActual = otrosNumeros[x]; | |
if (numeroActual < menor) { | |
menor = numeroActual; | |
} | |
} | |
System.out.printf("\nMenor: %d", menor); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment