Advertisement
mhrabbi

Find total number of even and odd number (java)

Feb 12th, 2020
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class EvenOddNumber {
  3.     public static void main(String args[])
  4.     {
  5.        
  6.         Scanner scan=new Scanner(System.in);
  7.        
  8.         int size;
  9.         int even=0;
  10.         int odd=0;
  11.        
  12.         System.out.println("Enter the Size of array: ");
  13.         size=scan.nextInt();
  14.        
  15.        
  16.         int [] arr =new int[size];
  17.        
  18.        
  19.        System.out.println("Enter elements in array");
  20.      
  21.        for(int i=0; i<arr.length; i++)
  22.         {
  23.           arr[i]=scan.nextInt();
  24.         }
  25.        
  26.        for(int i=0;i<arr.length;i++)
  27.        {
  28.            if(arr[i]%2==0)
  29.            {
  30.                even++;
  31.            }
  32.            else
  33.                odd++;
  34.                
  35.        }
  36.        
  37.        System.out.println("Total even number is: "+even);
  38.        System.out.println("Total odd number is: "+odd);
  39.        
  40.        scan.close();
  41.        
  42.        
  43.  
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement