Colorada numeros-desayuno
-
Upload
pablo-del-valle-carlos -
Category
Education
-
view
50 -
download
0
Transcript of Colorada numeros-desayuno
CONTAR UNA LISTA DE N NÚMEROS QUE INGRESARON POR TECLADO RECHAZANDO POR TECLADO EL CERO; LUEGO OBTENGA EL TOTAL DE NÚMEROS POSITIVOS QUE INGRESARON EL TOTAL NÚMEROS NEGATIVOS, EL MAXIMO Y EL MINIMO DE LOS MÚMEROS INGRESADOS.
import javax.swing.JOptionPane;public class numeros {
static int positivos=0;static int negativos=0;static int contarmax =Integer.MIN_VALUE;static int contarmin =Integer.MAX_VALUE;public static void main(String[] args) {
String dato=javax.swing.JOptionPane.showInputDialog("Ingrese el tamaño de la lista ");
int num=Integer.parseInt(dato);if(num==0){JOptionPane.showMessageDialog(null," EL NÚMERO CERO NO ES
VALIDO");}else{
int cont=1;while(cont<=num){String dato2=javax.swing.JOptionPane.showInputDialog("Ingrese
los elementos de su lista de números ");int numlista=Integer.parseInt(dato2);System.out.println(numlista);if(numlista>0){
positivos=positivos+1;}else{
negativos=negativos+1;}if(numlista>contarmax){
contarmax=numlista;}if(numlista<contarmin){
contarmin=numlista;}cont=cont+1;}System.out.println("El MAYOR NÚMERO ES :" + contarmax);System.out.println("El MENOR NÚMERO ES :" + contarmin);System.out.println("EL TOTAL DE NÚMEROS POSITIVOS ES : " +
positivos);System.out.println("EL TOTAL DE NÚMEROS NEGATIVOS ES : " +
negativos);}}
}
EJEMPLO: