Question

Write a program that takes n integer numbers from the user, and then counts the number...

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 ))

Homework Answers

Answer #1

/* 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

*/

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Assembler lanaguage program   The program is to prompt the user to enter a number between 2...
Assembler lanaguage program   The program is to prompt the user to enter a number between 2 and 100. Reject any invalid user inputs and terminate the program if invalid inputs are entered. Print each even number from 2 to the user entered number. Sum these even numbers and print the sum. Print each odd number from 1 to the user entered number. Sum these odd numbers and print the sum. Exit the program when the output is complete. The output...
Write a C++ program to prompt a user for a positive integer and print the number...
Write a C++ program to prompt a user for a positive integer and print the number of even and odd digits (0 is even). Sample run: Enter a positive integer: -4580 Invalid. Enter a positive integer: 12146 2 odd digits 3 even digits
Write a function that takes two integer inputs and returns the sum of all even numbers...
Write a function that takes two integer inputs and returns the sum of all even numbers between these inputs, and another function that takes two integer inputs and returns the sum of odd numbers between these inputs .In main function, the program will asks the user to enter two integer numbers and then passes them to these two functions and display the result of each of them.         [0.5 mark] (BY USING C PROGRAM)
in c++ Write a C++ program that asks the user to enter an integer number and...
in c++ Write a C++ program that asks the user to enter an integer number and prints it back "vertically" to the screen. Use recursion in your solution. As an example of how the program will work: Please enter an integer: 12345 The integer you entered will print vertically as: 1 2 3 4 5
1- Write a program to print only the even numbers from 100 to 200 2- Write...
1- Write a program to print only the even numbers from 100 to 200 2- Write a program to print the odd numbers from 22 – 99 3- Write a program to calculate howe many even number from 10 to 120 1- Write a program to find only the even numbers for 12 different numbers 2- Write a program to find the odd numbers for 10 different numbers 3- Write a program to calculate howe many even number and how...
Write a complete C++ program asking the user to enter numbers one by one. User enters...
Write a complete C++ program asking the user to enter numbers one by one. User enters only whole numbers 0 and 10. Once the user enters 0, then the program should print sum of only odd numbers entered by user prior to 0. A valid scenario given below: Enter a number: 5 Enter a number: 3 Enter a number: 2 Enter a number: 3 Enter a number: 8 Enter a number: 0 Sum of the odd numbers you entered is...
1)Write a program that asks a user for a number. If (and only if) the number...
1)Write a program that asks a user for a number. If (and only if) the number is greater than zero print “The number is valid” 2)Write a program that asks a user for a grade. If (and only if) the grade is greater than zero and less than 101, print “The grade is valid” 3)Write a program that asks a user how many widgets they want to buy and prints out what the user should pay. Widgets costs 10 dollars....
Collapse Write a program that prompts the user to input a positive integer. It should then...
Collapse Write a program that prompts the user to input a positive integer. It should then output a message indicating whether the number is a prime number. (Note: An even number is prime if it is 2. An odd integer is prime if it is not divisible by any odd integer less than or equal to the square root of the number.) Turn in: Your source code for with The name of your program as a comment at the top...
Write a program that asks the user to enter two integer numbers. the main function then...
Write a program that asks the user to enter two integer numbers. the main function then passes these numbers to a function named exp that calculates the multiplication of these numbers and print the exponential value of the result of multiplication
The Java program should sum the odd integers from 1 to the integer that the user...
The Java program should sum the odd integers from 1 to the integer that the user enters. For example, if the user enters 30, the program should sum the odd integers from 1 to 30.   Print "Please enter a positive nonzero integer." Declare a Scanner and obtain an integer from the user.   Use a Do...while statement and calculate the sum Use the integer that the obtained from the previous step for the loop-continuation condition. Display the sum Print the sum...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT