Java Reference
In-Depth Information
Clearly, you must initialize the variables zeros , evens , and odds to zero. You can
initialize these variables when you declare them.
1. Initialize the variables.
2. Prompt the user to enter 20 numbers.
3. For each number in the list:
a. Get the next number.
b. Output the number (echo input).
c.
MAIN
ALGORITHM
If the number is even:
{
i.
Increment the even count.
ii.
If the number is zero, increment the zero count.
}
otherwise,
Increment the odd count.
4. Print the results.
Before writing the Java program, let's describe Steps 1 through 4 in more detail. It
will be much easier for you to then write the instructions in Java.
1. Initialize the variables. You can initialize the variables zeros ,
evens , and odds when you declare them.
2. Use an output statement to prompt the user to enter 20 numbers.
3. For Step 3, you can use a for loop to process and analyze the 20
numbers. In pseudocode, this step is written as follows:
for (counter = 1; counter <= 20; counter++)
{
a.
get
the number;
b.
output
the number;
c.
switch (number % 2)
//check the remainder
{
case 0:
increment the even count;
if (number == 0)
increment the zero count;
break ;
 
Search WWH ::




Custom Search