Wednesday, February 8, 2017

Write a Java Program to display all Duck Number between 1 to 500 .

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 Duck2
{
public static void main(String...alt)throws Exception
{
for(int j=1;j<=500;j++)
{
int count=0;
String n=Integer.toString(j);
for(int i=0;i<n.length();i++)
if(n.charAt(i)=='0')
count++;
if(count>0)
System.out.println(j);
}
}
}

Share this

0 Comment to "Write a Java Program to display all Duck Number between 1 to 500 ."

Post a Comment