0% found this document useful (0 votes)
3 views2 pages

5 Digit - Duck Number

The document contains two Java programs: one checks if a 5-digit number is a duck number (contains the digit '0') and the other checks if a number is a palindrome (reads the same forwards and backwards). If the input for the duck number program is not a 5-digit number, it displays an invalid number message. The palindrome program reverses the number and compares it to the original to determine if it is a palindrome.

Uploaded by

afan24168
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

5 Digit - Duck Number

The document contains two Java programs: one checks if a 5-digit number is a duck number (contains the digit '0') and the other checks if a number is a palindrome (reads the same forwards and backwards). If the input for the duck number program is not a 5-digit number, it displays an invalid number message. The palindrome program reverses the number and compares it to the original to determine if it is a palindrome.

Uploaded by

afan24168
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

5 DIGIT - DUCK NUMBER

Write a program to enter a 5-digit number and check whether it is a duck


number or not. A number is said to be duck number if 0 is present in it.
If the user doesn’t enter a 5-digit number, display the message invalid
number.

import java.util.*;
public class duck
{
public static void main(String[]args)

{
Scanner in = new Scanner (System.in);
int n,p=1,d;
System.out.println("Enter the number");
n=in.nextInt();
if(n>=10000 && n<=99999)
{
while(n!=0)
{
d=n%10;
p=p*d;
n=n/10;
}
if(p==0)
System.out.println("Duck number");
else
System.out.println("Not a duck number");
}
else
System.out.println("Invalid number"); } }
PALINDROME NUMBER
Eg: 121 (Reversing the number = 121)
121 is a palindrome number
123 (Reversing the number = 321)
123 is not a palindrome number

import java.util.*;
public class palindrome
{
public static void main(String[]args)

{
Scanner in = new Scanner (System.in);
int n,p=0,d,n1;
System.out.println("Enter the number");
n=in.nextInt();
n1=n;
while(n!=0)
{
d=n%10;
p=p*10+d;
n=n/10;
}
if(p==n1)
System.out.println("Palindrome number");
else
System.out.println("Not a Palindrome number:");
}
}

You might also like