CORONA Number – Java Program

Write a program to accept a number and check whether it is a CORONA number or not.

CORONA NUMBER: A number whose all digits are odd.
Example: 3975 – all digits are odd

import java.util.Scanner;
class CoronaNumber
{
    public static void main(String args[])
    {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter a number");
        int n=in.nextInt();
        int flag=1;
        
        //check corona number
        int t=n;
        while(t>0) // taking out digits
        {
            int d=t%10;
            if(d%2==0)//condition to check even number
            {
                flag=0;
                break;
            }
            t=t/10;
        }
        if(flag==1)
            System.out.println(n+" is a Corona Number");
        else
            System.out.println(n+" is not a Corona Number");
    }
}

3 thoughts on “CORONA Number – Java Program”

Leave a Comment

Your email address will not be published. Required fields are marked *