Write a program to accept a number and check whether it is a duck number or not. A Duck number is a number that has zeroes present in it, but there should be no zero present at the beginning of the number.  For Example 1204, 6702, 1000

watch java videos here
https://www.youtube.com/user/trushnatej

import java .io.*;
class DuckNumber
{
    public static void main()throws IOException
    {
        BufferedReader br=new BufferedReader
            (new InputStreamReader(System.in));
        System.out.println("Enter a no.");
        int num =Integer.parseInt(br.readLine());
        boolean first=false;
        boolean flag=false;
        int rem=0;
        while(num!=0)
        {
            rem=num%10;
            num=num/10;
            if(rem==0)
                flag=true;
        }
        if(rem==0)
        {
            first=true;
        }
        if(flag==true&&first==false)
        {
            System.out.println("Duck Number");
        }
        else 
        {
            System.out.println("Not a Duck number");
        }

    }
}

Output:
Enter a no.
1204
Duck Number

For other java programs click
https://java4school.com/bubble-sort-binary-search

LEAVE A REPLY

Please enter your comment!
Please enter your name here