Number Assignment
Number Assignment
1 Write a Program in Java to input a number and check whether it is a Duck Number or not.
Note: A Duck number is a number which has zeroes present in it, but there should be no zero
present in the beginning of the number. For example 3210, 7056, 8430709 are all duck numbers
whereas 08237, 04309 are not.
2 Write a Program in Java to input a number and check whether it is a Pronic Number or
Heteromecic Number or not.
Pronic Number : A pronic number, oblong number, rectangular number or heteromecic number,
is a number which is the product of two consecutive integers, that is, n (n + 1).
Let’s understand the concept of Harshad Number through the following example:
The number 18 is a Harshad number in base 10, because the sum of the digits 1 and 8 is 9 (1 + 8
= 9), and 18 is divisible by 9 (since 18 % 9 = 0)
The number 1729 is a Harshad number in base 10, because the sum of the digits 1 ,7, 2 and 9 is
19 (1 + 7 + 2 + 9 = 19), and 1729 is divisible by 19 (1729 = 19 * 91)
The number 19 is not a Harshad number in base 10, because the sum of the digits 1 and 9 is 10 (1
+ 9 = 10), and 19 is not divisible by 10 (since 19 % 10 = 9)
The first few Harshad numbers in base 10 (decimal) are:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42, 45, 48, 50, 54, 60, 63, 70, 72, 80,
81, 84, 90, 100, 102, 108, 110, 111, 112, 114, 117, 120, 126, 132, 133, 135, 140, 144, 150, 152,
153, 156, 162, 171, 180, 190, 192, 195, 198, 200 etc.
4 Write a Program in Java to input a number and check whether it is a Disarium Number or not.
Note: A number will be called DISARIUM if sum of its digits powered with their respective
position is equal to the original number.
Fibonacci Series:
The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …
6 A special two-digit number is such that when the sum of the digits is added to the product of its
digits, the result is equal to the original two-digit number.
Example:
Consider the number 59.Sum of digits = 5+9=14
Product of its digits = 5 x 9 = 45
Sum of the digits and product of digits = 14 + 45 = 59
Write a program to accept a two-digit number. Add the sum of its digits to the product of its
digits. If the value is equal to the number input, output the message “special-two digit number”
otherwise, output the message “Not a special two-digit number”.
7 Write a Program in Java to input a number and check whether it is an Automorphic Number or
not.
Note: An automorphic number is a number which is present in the last digit(s) of its square.
Example: 25 is an automorphic number as its square is 625 and 25 is present as the last digits
8 A Smith number is a composite number, the sum of whose digits is the sum of the digits of its
prime factors obtained as a result of prime factorization (excluding 1). The first few such
numbers are 4, 22, 27, 58, 85, 94, 121 ………………..
Examples:
1. 666
Prime factors are 2, 3, 3, and 37
Sum of the digits are (6+6+6) = 18
Sum of the digits of the factors (2+3+3+(3+7)) = 18
2. 4937775
Prime factors are 3, 5, 5, 65837
Sum of the digits are (4+9+3+7+7+7+5) = 42
Sum of the digits of the factors (3+5+5+(6+5+8+3+7)) = 42
Write a program to input a number and display whether the number is a Smith number or not.
9 WAP to check the input number is a tech-number or not.
A tech number has even numbers of digits. If the number is split into two equal halves, then the
square of sum of these halves is equal to the number itself. Example:
3025
(30 + 25) 2 = 552 = 3025 is a tech number
10 Write a program to input a number. Count and print the frequency of each digit present in that
number. The output should be given as:
Sample Input: 44514621
Sample Output:
=====================
Digit Frequency
=====================
1 2
2 1
4 3
5 1
6 1
11 Write a program to input a string (word). Convert it into lowercase letters. Count and print the
frequency of each alphabet present in the string. The output should be given as:
Sample Input: Alphabets
Sample Output:
==========================
Alphabet Frequency
==========================
a 2
b 1
e 1
h 1
l 1
p 1
s 1
t 1
12 Write a Program in Java to input 2 numbers and find their Greatest Common Divisor (GCD).
Note: If the 2 numbers are 54 and 24, then the divisors (factors) of 54 are: 1, 2, 3, 6, 9, 18, 27, 54.
Similarly the divisors (factors) of 24 are: 1, 2, 3, 4, 6, 8, 12, 24.
The numbers that these two lists share in common are the common divisors (factors) of 54 and
24: 1, 2, 3, 6.
The greatest (highest) of these is 6. That is the greatest common divisor or the highest common
factor of 54 and 24.
13 Write a program in JAVA to find the Prime factors of a number.
Prime factors of a number are those factors which are prime in nature and by which the number
itself is completely divisible (1 will not be taken as prime number).