ClassifyNumbers

ClassifyNumbers - //Step 1...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
u //******************************************************** // Author: D.S. Malik // Program: Classify Numbers // This program counts the number of odd and even numbers. // The program also counts the number of zeros. //******************************************************** / import java.util.*; i public class ClassifyNumbers { static Scanner console = new Scanner(System.in); static final int N = 20; public static void main (String[] args) { //Declare the variables int counter; //loop control variable int number; //variable to store the new number int zeros = 0; //Step 1 int odds = 0; //Step 1 int evens = 0;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //Step 1 System.out.println("Please enter " + N + " integers, positive, " + "negative, or zeros."); //Step 2 for (counter = 1; counter <= N; counter++) //Step 3 { number = console.nextInt(); //Step 3a System.out.print(number + " "); //Step 3b //Step 3c switch (number % 2) { case 0: evens++; if (number == 0) zeros++; break; case 1: case -1: odds++; }//end switch }//end for loop System.out.println(); //Step 4 System.out.println("There are " + evens + " evens, " + "which also includes " + zeros + " zeros"); System.out.println("Total number of odds is: " + odds); } }...
View Full Document

Page1 / 2

ClassifyNumbers - //Step 1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online