Duck Number Program in Java1 min read

In this tutorial, we will learn about the Duck number with examples and write a java program for duck numbers. Before that, you may go through the following topics in java.

What is a Duck Number?

A number is said to be a duck number if it is a positive integer number with zeroes in it. The digit zero (0) must not be present at the beginning of the number but can be present anywhere except the initial digit.

Example of duck number:

  • 3210 is a duck number.
  • 0183 is not a duck number because there is a zero present at the beginning of the number.
  • 00132 is also not a dick number.

Now you have understood the Duck number, let us do a program to check duck numbers in java.


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

Output:

//Run: 1
Enter a positive integer: 2015
2015 is a Duck Number

//Run: 2
Enter a positive integer: 00124
124 is not a Duck Number

//Run: 3
Enter a positive integer: 11245
11245 is not a Duck Number

You can create a separate Boolean function that will return true or false like the flag that is working in this program. Hope this article was helpful on Duck Number Program in Java


MORE

C Program to search an element in an array using Pointers

A separate function( search_function()) will be created where the array pointer will be declared and the searched element along with the size of an array …

C Program to find the sum of the digits of a number using recursion function

This C program calculates the sum of digits of a given number using recursion. Here’s a concise explanation: Function Definition: sumDigits(int n) This function calculates …

C program to find factorial of a numberĀ using Ternary operator with Recursion

Recursion refers to the function calling itself directly or in a cycle. Before we begin, you should have the knowledge of following in C Programming: …

C Program to Add Two Numbers Using Call by Reference

The program takes the two numbers from the user and passes the reference to the function where the sum is calculated. You may go through …

Find the output ab, cd, ef, g for the input a,b,c,d,e,f,g in Javascript and Python

In this tutorial, we will write a program to find a pairs of elements from an array such that for the input [a,b,c,d,e,f,g] we will …

String Pattern Programs in C

In this tutorial, we will write various C pattern programs for String. Before that, you may go through the following topics in C. for loop …