Duck Number

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 java.util.*;

class duck

{//class duck opens

    public static void main(String[]args)

    {//main method opens 

       Scanner sc=new Scanner(System.in);

       System.out.println("Enter a no");

       int n=sc.nextInt();//variable n to accept the no

       int p=1,r=0;//variable p to store the product,varible r to extract the digits 

       while(n>0)

       {

        r=n%10;

        p=p*r;

        n=n/10;

       }

       if(p==0)

    System.out.println("It is a duck no");

     else

    System.out.println("It is  not a duck no");

    }//main method closes

}  //class closes

No comments:

Post a Comment

any problem in any program comment:-

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...