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

String Methods in Java for ICSE Class 10: 25 Output Questions with Answers
ICSE Class 10 Computer Applications practice on String class methods: length, charAt, indexOf, lastIndexOf, substring, replace, trim, compareTo, equals and more, with 25 board-style output questions and step-by-step answers.

Special Number Programs in Java for ICSE: Armstrong, Spy, Neon, Disarium, Pronic and More
Every special number asked in ICSE Computer Applications – prime, perfect, Armstrong, palindrome, automorphic, neon, spy, Niven, duck, buzz, Disarium, special and pronic numbers – with definitions, examples and one complete Java program that checks them all.

Math Library Methods in Java for ICSE Class 9 (with Outputs)
ICSE Class 9 Computer Applications notes on the Java Math class: sqrt, cbrt, pow, abs, max, min, ceil, floor, round, rint and random, with return types, tricky negative-number outputs and Java expressions for formulas.