sábado, 25 de febrero de 2023

Booleano

 package operadores;

import javax.swing.JOptionPane;

public class persona {

public static void main(String[] args) {

int numero;

boolean hay_negativos = false;

for (int i = 1; i <= 10; i++) {

numero = Integer.parseInt(JOptionPane.showInputDialog("Digite un numero: "));

if (numero < 0) {

hay_negativos = true;

}

}

if (hay_negativos == true) {

System.out.println("Hay negativo");

} else {

System.out.println("No hay negativos");

}

}

}

No hay comentarios:

Publicar un comentario