Class 10 Class 11 Class 12

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.");

3 replies on “Duck Number in Java”

Sir,a program is given which states that :
Write a program to create a square matrix of size [m × m] of type integer.

The value of ‘m’ is entered by the user and ensure that m > 3 and m < 10.

For an invalid size, display a suitable error message.

Now allow the user to enter integers into this matrix.

Once the array is full with integers, display the elements that fall below the left diagonal.

Sir,a program is given which states that:
WAP in Java to accept some nos to create m×m matrix.The value of ‘m’ is entered by the user and ensure that m > 2 and m < 10.Now display the elements below the left diagonal of that matrix.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.