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
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.
divide even number by 2 and what is the reminder? duvid odd number by 2 and...
divide even number by 2 and what is the reminder? duvid odd number by 2 and what is the reminder? here modulus is a remiander function. MY_ARRAY[] is an array if 49 elements or DINT[49]. Create four versions of structured text code that sets all even elements of MY_ARRAY[] =3 and all odd elements = 7 using. You can use any function or construct in structured text however each version will contain only 1 type of loop construct: 1) 1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT