A deadly Duck Number
watch java videos here https://www.youtube.com/user/trushnatej
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
An effortless Bubble Sort & Binary Search
Related Posts
Continue learning with these related articles
Sum of First n Natural Numbers in Java (Loop and Formula)
Find the sum of the first n natural numbers in Java with a for loop, a while loop and the formula n(n + 1)/2, with a dry run and the sums of even numbers, odd numbers, squares and cubes.
Prime Number Program in Java: Check a Number and Print Primes in a Range
Check whether a number is prime in Java by counting its factors, a faster square-root method with isPrime(), and a program that prints all prime numbers in a range.

Encapsulation, Access Specifiers and Scope of Variables in Java for ICSE Class 10
ICSE Class 10 Computer Applications notes on encapsulation: private, default, protected and public access, data hiding with getter and setter methods, instance vs static (class) variables, local variables and scope, with a solved BankAccount program.