domingo, 15 de mayo de 2011

INGRESAR LA CANTIDAD DE NUMEROS POSITIVOS Y NEGATIVOS UTILIZANDO WHILE

import javax.swing.JOptionPane;
public class ejemp04_while{
    public static void main(String args[]){
     String entrada=JOptionPane.showInputDialog("ingrese cantidad de numeros negativos");
     int neg= Integer.parseInt(entrada);
     String cant=JOptionPane.showInputDialog("ingrese cantidad de numeros positivos");
     int pos= Integer.parseInt(cant);
     int n;
     int i=1;
     while(i<=pos ){
     String nume  = JOptionPane.showInputDialog("ingrese el num"+i+":");
       int num =Integer.parseInt(nume);
       if (num > 0){
          
           pos=pos+1;
         }
            else

           if (num < 0){
              
               neg=neg+1;
               }
            else
            {
            JOptionPane.showMessageDialog (null,"el numero ingresado es cero");
             }
            i=i+1;
             {
           JOptionPane.showMessageDialog (null,"total de numeros negativos:" + neg);
           JOptionPane.showMessageDialog (null, "total de numeros positivos:" + pos);
              }

           }
       }
     }

No hay comentarios:

Publicar un comentario