Wednesday, February 8, 2017

Write a Program in Java to input a number and check whether it is a Duck Number or not.

Note: A Duck number is a number which has zeroes present in it,
but there should be no zero present in the beginning of the number.
For example 3210, 7056, 8430709 are all duck numbers whereas 08237, 04309 are not. */

import static java.lang.System.out;
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Duck
{
public static void main(String...alt)throws Exception
{
int count=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
out.println("Enter a Number : ");
String n=br.readLine();
for(int i=0;i<n.length();i++)
if(n.charAt(i)=='0')
count++;
if(n.charAt(0)=='0' && count>0)
System.out.println(n+" is not duck no.");
else
System.out.println(n+" is duck no.");
}
}

Share this

0 Comment to "Write a Program in Java to input a number and check whether it is a Duck Number or not."

Post a Comment