Define a class to accept a 3 digit number and check whether it is a duck number or not.
Note: A number is a duck number if it has zero in it
Example1:
Input: 2083
Output: Invalid
Example 2:
Input: 103
Output: Duck number
        
Solution:
,
 


  
import java.util.*;
class duck 
{
  public static void main(String args[]) 
  {
      int num;boolean check=false;
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter the number:");
      num = sc.nextInt();

      while(num!=0)
      {
          int d=num%10;
          if(d==0)
              check=true;
          num/=10;
      }
      
      if(check)
          System.out.println("Duck Number");
      else
          System.out.println("Not Duck Number");
  }
}
  
                                              

                                                           
                                                                  


                                            



Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com