NPS INTERNATIONAL, CHENNAI
Perumbakkam, Chennai – 600 100
ROLL NO:
CERTIFICATE
Certified that this is a bonafide record of
Name
practical work done by
………………………………………….in the
subject Computer Science during the
academic year 2024 to 2025.
Date: Teacher-in-Charge
Submitted to the Practical Examination in NPS
International,
Chennai held on ………………………..
Principal Examiner
Index
S.No Date TOPIC Page. Signature
No
1. 10.06.24 Adam Prime Number
2. 11.06.24 Composite Magic
3. 18.06.24 Circular Prime
4. 02.07.24 Goldbach Number
5. 09.07.24 Project Date
6. 15.07.24 Lucky Number
7. 16.07.24 Bouncy Number
8. 30.07.24 Automorphic Number
9. 05.08.24 Spy Number
10. 06.08.24 Disarium Number
11 12.08.24 Armstrong Number
12. 19.08.24 Snowball String
13. 27.08.24 Decode
14. 03.09.24 Word Count (vowel and consonant)
15. 05.09.24 Capital Letter
16. 14.10.24 Mix (two words into one)
17. 18.10.24 Bubble Sort - Strings
18. 21.10.24 Selection Sort numbers
19. 24.10.24 Insertion Sort numbers
20. 28.10.24 Convert Day number
21. 30.10.24 Rotate Matrix
22. 04.11.24 Boundary Elements – Display and sum
23. 11.11.24 Binary Search (with sorting and recursion)
24. 18.11.24 Mixer – (2 arrays objects)
25. 25.11.24 Transpose of Matrix
Program 1
ADAM PRIME NUMBER
ALGORITHM:
Step 1: Start
Step 2: Declare a method to check if the given formal parameter is a prime number.
Step 3: Declare another method to check if the given formal parameter is an Adam number.
Step 4: Declare main() method
Step 5: Accept m and n from user using Scanner class
Step 6: Check for invalid condition
Step 7: If the condition is valid, Start Printing the Adam Prime Integers
Step 8: Using a for loop, check if each number between the range m and n is an Adam Prime number
Step 9: If it is an Adam Prime number, increment a counter variable and also print the number
Step 10: Outside the for loop, if the counter is 0, print “NIL”
Step 11: If there is a non-zero value in counter, print it as the frequency of Adam Prime numbers
Step 12: Stop
CODE:
import java.util.*;
public class PrimeAdam {
static boolean prime(int n) {
int c = 1;
for (int i = 1; i <= n; i++) { //Checking prime
if (n % i == 0)
c *= i;
}
return (c == n) ? true : false;
}
static boolean Adam(int n) {
int t = n, rev = 0;
4
while (t > 0) { //Reversing number
rev = (rev * 10) + (t % 10);
t /= 10;
}
int n_sq = n * n, rev_sq = rev * rev, new_sq_rev = 0;
while (n_sq > 0) { //Reversing square of reversed number
new_sq_rev = (new_sq_rev * 10) + (n_sq % 10);
n_sq /= 10;
}
return (new_sq_rev == rev_sq) ? true : false;
}
public static void main() {
Scanner sc=new Scanner (System.in);
System.out.print("INPUT:\nm = ");
int m = sc.nextInt();
System.out.print("n = ");
int n = sc.nextInt(), c = 0;
System.out.println("OUTPUT: ");
if (m > n) {
System.out.println("Invalid Input");
System.exit(0);
}
else if (m <= n) {
System.out.println("The Adam Prime integers are: ");
for (int i = m; i <= n; i++) {
if (prime(i) && Adam(i)) //Checking if i is Adam Prime with boolean returned by methods
c++; //Increasing frequency of Adam Prime numbers
if (prime(i) && Adam(i))
System.out.print(c == 1 ? i : ", " + i);
}
5
System.out.print(c == 0 ? "NIL" : "");
System.out.println("\nFrequency of Adam Prime integers are: \n" + c);
}
}
}
VARIABLE DESCRIPTION:
Variable Data type Purpose
m int Lower limit of range
n int Upper limit of range /
Formal parameters in
methods
i int Looping variable used in
for-loops
c int Counter variable / Variable
used in prime method for
product of all factors
t int Temporary variable to store
n
rev int Reverse of original number
n_sq int Original number’s square
rev_sq int Reversed number’s square
new_sq_rev int Reverse of reversed
number’s square
OUTPUT: