Duck Number in Java

A duck number is a positive integer that has one or more zeroes present in it. However, the number should not begin with zero.

For instance, 1205, 500, etc. are duck numbers.

Write a program in Java to accept a positive integer from the user, and check whether it is a duck number.

class Duck{
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(;
        System.out.print("Positive integer: ");
        int num = Math.abs(Integer.parseInt(br.readLine()));
        int count = 0;
        for(int i = num; i > 0; i /= 10){
            int digit = i % 10;
            if(digit == 0)
        if(count > 0)
            System.out.println(num + " is a duck number.");
            System.out.println(num + " is not a duck number.");

Leave a Reply

%d bloggers like this: