Skip to main content

Program in Java accept a number and if all the digits are odd. Then it is a corona number

 To accept a number and if all the digits are odd. Then it is a corona number


import java.util.Scanner;
class corona
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number: ");
int n=sc.nextInt();
int c=0,odd=0;
while(n>0)
{
int r = n%10;
if(r%2!=0)
{
odd=odd+1; //count the odd digits
}
//count digits
c=c+1;
n=n/10;
}
if(c==odd)
System.out.println("Corona number");
else
System.out.println("Non-corona number");
}
}

Popular posts from this blog