**Tags**

https://leanpub.com/javaintensivecodingbootcamplearnlanguagebasicsandalgorithm

In Mathematics, the Duck number is defined as a number which has zeroes present in it. However, not in the beginning of the number. For example 3210, 7056 are Duck numbers. But not 0321, or 0756.

//code to find a duck number package fun.sanjibsinha; //check whether a number is Duck Number or not. import java.util.Scanner; class DuckNumber{ public int checkingDuck(String num){ int len = num.length(); int countZero = 0 ; char myChar; for(int i = 1; i < len; i++) { myChar = num.charAt(i); if(myChar == '0') countZero++; } return countZero ; } } public class ProblemEightyTwo { static int num = 0; static String str; static char digitAtIndexZero; public static void main(String[] args){ DuckNumber myDuck = new DuckNumber(); Scanner sc = new Scanner(System.in); System.out.println("Enter a number to check whether the number is a Duck number or not: "); num = sc.nextInt(); String num1 = Integer.toString(num); str = Integer.toString(num); digitAtIndexZero = str.charAt(0); if( myDuck.checkingDuck(str) > 0 && digitAtIndexZero != '0') System.out.println("It is a duck number"); else System.out.println("It is not a duck number"); } } We are taking inputs from the users to examine the nature of the number.

Let us check the output as follows:

//output Enter a number to check whether the number is a Duck number or not: 123 It is not a duck number Enter a number to check whether the number is a Duck number or not: 1023 It is a duck number