Write a program that takes n integer numbers from the user, and then counts the number of even numbers and odd numbers and print them to the screen.
Sample Output:
Enter how many numbers you have: 10
Enter the 10 numbers: 1 3 19 50 4 10 75 20 68 100
The number of even numbers is: 6
The number of odd numbers is: 4
(( in java ))
/* Program written in Java language using netbean 8.0 and JDK 1.8 */
package Main;
import java.util.Scanner;
public class OddEvenCount {
public static void main(String[] args)
{
// Scanner class accept
input from user
Scanner scanner=new
Scanner(System.in);
int array[]=new
int[100];// create maximum size array
System.out.println("Enter Count of element for array :: ");
int
size=scanner.nextInt(); //get size from user and hold it in
size
System.out.println("Enter Elements for araay :: ");
//get all entered
elements in array
for (int i = 0; i <
size; i++) {
array[i]=scanner.nextInt();
}
int evencount=0;
int oddcount=0;
//travel all element
again for counting odd and even elemets
for (int i = 0; i <
size; i++) {
if(array[i]%2==0){//condition for even element
evencount++;
}
else//otherwise element is odd
oddcount++;
}
System.out.println("Odd
Elements count is ::"+oddcount);
System.out.println("Even
Elements count is ::"+evencount);
}
}
/*
output
Enter Count of element for array ::
10
Enter Elements for araay ::
1 3 19 50 4 10 75 20 68 100
Odd Elements count is ::4
Even Elements count is ::6
BUILD SUCCESSFUL (total time: 30 seconds)
*/
/*
Screenshot with output
*/
Get Answers For Free
Most questions answered within 1 hours.