Advertisement
Vladkoheca

OddOrEven.java

Oct 23rd, 2024
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2. public class OddOrEven {
  3.     public static void main(String[] args) {
  4.         Scanner sc = new Scanner(System.in);
  5.  
  6.         System.out.print("Enter how many numbers: ");
  7.         int n = sc.nextInt();
  8.  
  9.         int odd = 0;
  10.         int even = 0;
  11.  
  12.         for (int i = 1; i <= n; i++) {
  13.             System.out.print("Enter number " + i + ": ");
  14.             int x = sc.nextInt();
  15.             if (x % 2 == 0) {
  16.                 even++;
  17.             } else {
  18.                 odd++;
  19.             }
  20.         }
  21.         System.out.println("Odd count: " + odd);
  22.         System.out.println("Even count: " + even);
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement