-
-
Save parzibyte/0bd68c5303d928a67c922b2502eeb824 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
public static void serieMaximoMinimo() { | |
Scanner sc = new Scanner(System.in); | |
ArrayList<Integer> numeros = new ArrayList<>(); | |
while (true) { | |
System.out.println("Ingresa un número: "); | |
int numero = sc.nextInt(); | |
if (numero == 0) { | |
break; | |
} else { | |
numeros.add(numero); | |
} | |
} | |
if (numeros.size() <= 0) { | |
System.out.println("No se ha introducido ningún valor correcto."); | |
} else { | |
int mayor = numeros.get(0); | |
int menor = numeros.get(0); | |
for (int numero : numeros) { | |
if (numero > mayor) { | |
mayor = numero; | |
} | |
if (numero < menor) { | |
menor = numero; | |
} | |
} | |
System.out.printf("Máximo: %d; Mínimo: %d", mayor, menor); | |
} | |
sc.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment