//********************************************************************************************
//Program that asks a user to input integers. The integers are then counts the number of odd
//even and 0's and outputs the count to the user
//********************************************************************************************
import java.util.*;
public class numberClassifier
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
int totalNum = 0;
int curNum = 0;
int zero = 0;
int odd = 0;
int even = 0;
boolean hasRunOnce = false;
System.out.print("Enter the integers you wish to have classified separated by spaces.: ");
while (console.hasNext() || (hasRunOnce == false))
{
hasRunOnce = true;
totalNum++;
curNum = console.nextInt();
if (curNum == 0)
{
zero++;
even++;
}
else
{
curNum = curNum % 2;
switch (curNum)
{
case 0: even++;
case 1:
case -1: odd++;
}
}
}
System.out.println();
System.out.println("Out of the " + totalNum + " numbers you enterred, " + zero +
" were zeros, " + odd + " were odd, and " + even +
" were even.");
}
}
Edited by WingedPanther, 08 June 2009 - 01:07 PM.
add code tags (the # button)


Sign In
Create Account

Back to top









