Practice Program Assignment 4
Practice Program Assignment 4
1. An Armstrong number is a positive m-digit number that is equal to the sum of the mth powers
of their digits. For example:
A Pronic number is a number which is the product of two consecutive integers, that is, a
number of the form n(n + 1). For example:
6= 2 x 3
12 = 3 x 4
20 = 4 x 5
Write a program in Java that will accept two positive integers ‘p’ and ‘q’, such that p < q and
as per user’s choice, will find out, within ‘p’ and ‘q’,
It is to be noted that
a. Your program should print an error message and will ask the user to make
choice between trying again or to exit, if by mistake he/she picks up a value for
‘q’ which happens to be less than ‘p.
b. Even if inputs are fine, it will not exit after producing the output, until the user
allows it to.
2. A Prime-Adam integer is a positive integer (without leading zeros) which is a prime as well as
an Adam number.
Prime number: A number which has only two factors, i.e. 1 and the number itself.
Example: 2, 3, 5, 7 … etc.
Adam number: The square of a number and the square of its reverse are reverse to each
other.
Example: If n = 13 and reverse of 'n' = 31, then,
(13)2 = 169
(31)2 = 961 which is reverse of 169
So, 13 is an Adam number.
Write a program in Java that will accept two positive integers m and n, where m is less than
n as user input. Display all Prime-Adam integers that are in the range between m and n
(both inclusive) and output them along with the frequency, in the format given below:
Test your program with the following data and some random data:
Example 1 Example 2
INPUT: INPUT:
m=5 m = 100
n = 100 n = 200
OUTPUT: OUTPUT:
THE PRIME-ADAM INTEGERS ARE: THE PRIME-ADAM INTEGERS ARE:
11 13 31 101 103 113
FREQUENCY OF PRIME-ADAM INTEGERS IS: 3 FREQUENCY OF PRIME-ADAM INTEGERS IS: 3
Test your Program for the following data and some random data.
SAMPLE DATA:
INPUT:
Encoded Message:
2312179862310199501872379231018117927
OUTPUT:
THE DECODED MESSAGE: Have a Nice Day
INPUT:
Encoded Message:
23 5 1 1 0 1 1 5 0 1 7 8 2 3 5 1 1 1 2 1 7 9 9 1 1 8 0 1 5 6 2 3 4 0 1 6 1 1 7 1 1 4 1 1 4 8
OUTPUT:
THE DECODED MESSAGE: Truth Always Wins