Question

Write a Java program that first asks the user how many numbers will be entered - let's call this positive integer n. Then the program takes input n integers (not ordered) and outputs how many even values and how many odd values have been entered. Input control: the input should be restricted to only integers between 0 and 100.

SAMPLE OUTPUT:
How many numbers in input? 10
Now enter 10 integers:
123
ERROR! Valid range 0 - 100. REENTER: 1
2
3
129
ERROR! Valid range 0 - 100. REENTER: 4
5
6
7
176
ERROR! Valid range 0 - 100. REENTER: 8
9
10
You entered 5 odd numbers and 5 even numbers.

Using while loops, for loops, and if and else statements.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.util.Scanner;

public class EvenOdd {

public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int[] nums;
int count, even = 0, odd = 0;

System.out.print("How many numbers in input? ");
count = input.nextInt();
nums = new int[count];
System.out.println("Now enter " + count + " integers: ");
for(int i = 1; i <= count; i++)
{
nums[i-1] = input.nextInt();...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Java Program For Restaurants
Homework Solution
$18.00
Java
Restaurants
Computer Science
Programming
Tips
Variables
Functions
Dollar Amounts
Functions
Input
Output
Statements
Multiplication
Bills
Percentage
Division
NumberFormat Class
Pyramid Using Asterisks in Java
Homework Solution
$30.00
Java
Programming
Codes
Algorithms
Computer Science
Statements
Variables
Loops
Input
Output
Integers
Strings
Asterisks
Symbols
Pyramid
Rows
Odd Numbers
Matrix Problem in Java
Homework Solution
$13.00
Java
Programming
Coding
Computer Science
Matrix
Diagonals
Input File
Output File
Integers
Loops
Conditions
Statements
Swapping Numbers
Random Values
Variables
Get help from a qualified tutor
Live Chats