Question

In: Computer Science

//----------------------------------------------------------------- // Counts the number of odd, even, and zero digits in an integer // input...

//-----------------------------------------------------------------
// 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!");
  

Solutions

Expert Solution

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!");
   }
}


Related Solutions

Counts the number of odd, even, and zero digits in an integer input value. Repeat until...
Counts the number of odd, even, and zero digits in an integer input value. Repeat until user does not want to continue. Develop the program in an incremental fashion. For example, write the part of the program, which inputs a single integer value and displays number of odd, even, and zero digits in that number. Submit your partial program for grading to make sure it works for the first few test cases. Below is an example execution of a partial...
Using for loop . Input an integer and identify whether it's EVEN OR ODD ( without...
Using for loop . Input an integer and identify whether it's EVEN OR ODD ( without using modulo operator ) using only <iostream> . C++ programming
Create an application that checks whether an integer is an odd or even number. Welcome to...
Create an application that checks whether an integer is an odd or even number. Welcome to the Odd/Even Checker! Enter an integer: ten Error! Invalid integer. Try again. Enter an integer: 10.3 Error! Invalid integer. Try again. Enter an integer: 10 The number 10 is even. Continue? (y/n): Error! This entry is required. Try again. Continue? (y/n): y Enter an integer: 9 The number 9 is odd. Continue? (y/n): n Specifications: Create a version of the Console class presented in...
Write a function name as 'checkEvenOrOdd' that checks the input value is odd or even number....
Write a function name as 'checkEvenOrOdd' that checks the input value is odd or even number. The main function is given: int main(){     int number;     cout << "Check number input: ";     cin >> number;     cout << "The input number " << number << " is " << checkEvenOrOdd(number) << endl;     return 0; } simple c++ code please
prove that if an even integer n is subtracted from an odd integer m. then m...
prove that if an even integer n is subtracted from an odd integer m. then m - n is odd.
prove that every integer is either even or odd but never both.
prove that every integer is either even or odd but never both.
Prove that every natural number is odd or even.
Prove that every natural number is odd or even.
Read four digits from the random numbers table. note the number of odd digits in the...
Read four digits from the random numbers table. note the number of odd digits in the selected numbers. Repeat the experiment 25 times. Obtain the probability distribution of the odd digits. Find mean and variance of the distribution
What is the probability that a randomly chosen four-digit integer has distinct digits and is odd?
What is the probability that a randomly chosen four-digit integer has distinct digits and is odd?
Write c code to determine if a binary number is even or odd. If it is...
Write c code to determine if a binary number is even or odd. If it is odd, it outputs 1, and if it is even, it outputs 0. It has to be less than 12 operations. The operations have to be logical, bitwise, and arithmetic.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT