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

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 …

Java Program to Find pair of Integers in Array whose sum is given Number

In this tutorial, we will write a program to find a pair of elements from an array whose sum equals a given number in java …

Program to Print Diamond Alphabet Patterns in C

In this tutorial, we will learn to write a C program to print Diamond patterns using alphabets/characters. However, in this tutorial, we will create a …

Half Diamond Pattern in C using Alphabets

In this tutorial, we will learn and code the half diamond alphabet patterns in C programming language. However, in this tutorial, we will create a …

Half Pyramid of Alphabets in C

In this tutorial, we will learn and code alphabet patterns in C programming language specifically the Half pyramid of alphabets in C programming. However, in …