Number PGM
Number PGM
Define a class to accept a 3 digit number and check whether it is a duck number or not. [15]
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
import java.util.*;
class Duck_number
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the number");
int n=sc.nextInt();
if(n<100||n>999)
{
System.out.println("Invalid input");
System.exit(0);
}
int rem=0,temp=0,n1=n;
while(n>0)
{
rem=n%10;
if(rem==0)
{
temp=1;
break;
}
n=n/10;
}
if(temp==1)
System.out.println(n1+" is a duck number");
else
System.out.println(n1+" is not a duck number");
}
}
Define a class to accept a number from user and check if it is an EvenPal number or not. (The number is said
to be EvenPal number when number is palindrome number (a number is palindrome if it is equal to its reverse)
and sum of its digits is an even number.) Example: 121 – is a palindrome number
Sum of the digits – 1+2+1 = 4 which is an even number
import java.util.*;
while (n> 0)
{
rem = n%10;
rev = rev*10 +rem;
sum = sum+rem;
n= n/10;
}
}
}
Define a class to accept a number and check whether it is a superspy number or not . A super spy number is a number where sum of
digit is equal to number of digit
Example:
N=1021
Sum of digit=1+0+2+1=4
Number of digit=4
Output: 1021 is a superspy number
import java.util.*;
}
}