Advertisements

Java program to check whether a number is duck number or not

NOTE:-A Number is said to be duck number when there's a zero in number. Ex:- 2014

import java.util.Scanner;

public class duck {

public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int num=sc.nextInt();
int c = 0;
int r;
while(num!=0)
{
r=num%10;
if(r==0)
c++;
num=num/10;


}
if(c>0)
System.out.println("It is a duck number");
else
System.out.println("It is not a duck number");
}
}