In: Computer Science
//-----------------------------------------------------------------
// Counts the number of odd, even, and zero digits in an
integer
// input value. Repeat as long as the user wishes to continue
//-----------------------------------------------------------------
public static void main(String[] args)
{
// Declare the identifiers
final int SENTINEL = -99;
// Declare the remaining identifiers ...
Scanner scan = new Scanner(System.in);
// Display the programmer's information
// Input an integer number
// Count the number of odd, even, and zero digits in
the number
// Display the counts
System.out.println("\nHave a nice day!");
import java.util.*;
public class HelloWorld
{
public static void main(String[] args) {
// Declare the identifiers
final int SENTINEL = -99;
// Declare the remaining identifiers ...
int n,odd=0,even=0,zero=0;
Scanner scan = new Scanner(System.in);
// Display the programmer's information
System.out.println("Program to Count the number of odd, even, and
zero digits in the number:");
while(true)
{
// Input an integer number
//reading number
System.out.print("Enter an integer:");
n =scan.nextInt();
// Count the number of odd, even, and zero digits in the
number
while(0<n)
{
int c=n%10;
if(c==0)
zero++;
else if(c%2==0)
{
even++;
}
else
odd++;
n=n/10;
}
// Display the counts
System.out.println("Even:"+even+"\nOdd:"+odd+"\nZero:"+zero);
//checking whether user what to continue or not
System.out.println("To stop enter -99:");
n = scan.nextInt();
if(n==SENTINEL)
break;
else
zero=even=odd=0;
}
System.out.println("\nHave a nice day!");
}
}