Advertisement
robeeeert

Proyecto1- Ejercicio 2 - Contador de pares impares positivos negativos

Apr 12th, 2023
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class p2 {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.         int cantidad;
  8.         int pares = 0;
  9.         int impar = 0;
  10.         int positivo = 0;
  11.         int negativo = 0;
  12.         int contador = 1;
  13.         int numeroIngresado;
  14.        
  15.         System.out.print("Ingrese la cantidad de digitos: ");
  16.         cantidad = sc.nextInt();
  17.    
  18.        
  19.         while (contador <= cantidad){
  20.             System.out.print("Digite el numero " + contador + " : ");
  21.             numeroIngresado = sc.nextInt();
  22.            
  23.             if (numeroIngresado % 2 == 0){
  24.                 pares ++;
  25.             }else{
  26.                 impar ++;
  27.             }
  28.             if (numeroIngresado > 0){
  29.                 positivo ++;
  30.                
  31.             }
  32.             else{
  33.                 negativo ++;
  34.             }
  35.            
  36.             contador ++;
  37.         }
  38.         System.out.println("Pares: " + pares);
  39.         System.out.println("Impares: " + impar);
  40.         System.out.println("Positivos: " + positivo);
  41.         System.out.println("Negativos: " + negativo);
  42.  
  43.     }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement