Duck Number Program in Java

A Duck number is a number which has zeroes present in it, but there should be no zero present in the beginning of the number. For example 3210


import java.util.Scanner;

public class DuckNumber
{
    public static void main(String[] args)
    {
        // TODO code application logic here
        int r, n, num;
        boolean flag=false;
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter number=");
        n = sc.nextInt();
        num = n;
        while (num > 0)
        {
            r = num % 10;
            if(r==0)
            {
                flag=true;
            }
            num = num / 10;
        }
        if(flag)
        {
            System.out.println("Duck Number");
        }
        else
        {
            System.out.println("Not Duck Number");
        }
        
    }
}


Output:

Enter number=205
Duck Number
What is Duck Number?
A Duck number is a number which has zeroes present in it, but there should be no zero present in the beginning of the number. For example 3210

What is Duck Number in Java?
A Duck number is a number which has zeroes present in it, but there should be no zero present in the beginning of the number. For example 3210

b. tech. bca icse java java tutorials learn java mca programs