Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created October 26, 2022 15:36
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/0bd68c5303d928a67c922b2502eeb824 to your computer and use it in GitHub Desktop.
Save parzibyte/0bd68c5303d928a67c922b2502eeb824 to your computer and use it in GitHub Desktop.
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