0% found this document useful (0 votes)
17 views60 pages

Final Copy Computer Project

Uploaded by

ritikraaj16
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)
17 views60 pages

Final Copy Computer Project

Uploaded by

ritikraaj16
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

1

ᵜASSESSMENT SHEETᵜ

➤NAME:- Ritik Raj


➤CLASS:- XI - A
➤ROLL NO:- 15
➤SESSION:- 2025-26
□SIGNATURES□

INTERNAL EXAMINER:-_____________________

EXTERNAL EXAMINER:-

PRINCIPAL:- _

2
ACKNOWLEDGEMENT
I would like to express my special thanks
of gratitude to Sir Manager and Ma’am
Principal for giving us the opportunity to
complete this project.

I would also like to thank my


computer teacher for her able guidance
and support in completing this project.

Ritik Raj

3
INTRODUCTION

This project consists of 20 programs on the


topics like Arrays, String, Methods and
functions, Constructors, data structure and
various other topics which have been
covered by us during the academic session.
Each program contains the algorithm,
program code, output and variable
description table to explain the
functionality well.

4
⩩INDEX⩩
S. No. Program Page no Signatures

1. CHARACTER MATRIX. 3-7

2. DATE AND MONTH. 8-13

3. PALINDROME 1P-18
PROGRAM.

P. GOLDBACH NUMBER. 19-23

5. MATRIX ROTATION. 2P-28

6. MATRIX SORTING. 29-3P

7. CIRCULAR QUEUE. 35-38

8. ACHILLES NUMBER. 39-P2

9. PRIME ADAM INTEGER. P3-P7

10. PRIME PALINDROME. P8-52

1
⫷Program-1⫸

Write a program to declare a square matrix m[][] of order


‘N’ where ‘N’ must be greater than 3 and less than 10.
Allow the user to accept three different characters from
the keyboard and fill the array according to the instruction
given below:
1. Fill the four corners of the square matrix with the
first character.
2. Fill the boundary of the matrix (except the four corners)
with the second character.
3. Fill the non-boundary elements of the matrix with the
third character.
Test your program with the following data and some random
data:
INPUT:
N=P
First character: @
Second character: ?
Third character: #
OUTPUT:
@??@
?##?
?##?
@??@

2
#ALGORITHM#
Step 1: Class fillMatrix created
Step 2: Size of the matrix is entered by the user.
Step 3: Condition is checked for size entered by the user.
Step 4: Characters to be filled in the matrix is entered by the user.
Step 5: Characters are filled according to the condition given in
the question.
Step 6: Resultant matrix is printed.

3
import [Link].*;
class FillMatrix
{
public static void main (String args [])

{
Scanner sc = new Scanner([Link]);
[Link]("Matrix size: ");
int n = [Link]();
if(n < 4 || n > 9){
[Link]("Size out of range!")

return;
}

char m[][] = new char[n][n];


[Link]("First character: "); char
first = [Link]().charAt(0);
[Link]("Second character: ");
char second = [Link]().charAt(0);
[Link]("Third character: "); char
third = [Link]().charAt(0);
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i == 0 || j == 0 || i == n - 1 || j == n -
1) m[i][j] = second;
4
else

5
m[i][j] = third;
}
}

m[0][0] = first;
m[n - 1][n - 1] = first;
m[0][n - 1] = first;
m[n - 1][0] = first;
[Link]("Resultant Matrix:");
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
[Link](m[i][j] + "\t");
}

[Link]();
}
1OUTPUT1

6
::VDT::
VARIABLE DATA-TYPE DESCRIPTION

N int Size of the matrix

M char Matrix

I int Loop variable

J int Loop variable

First char First character

Second char second character

Third char third character

7
⫷PROGRAM-2⫸

Design a class Convert to find the date and the month from a
given day number for a particular year.
Example: If day number is 6P and the year is 2020, then the
corresponding date would be: March P, 2020 i.e. (31 + 29 + P
= 6P).

#ALGORITHM#
Step1: Class Convert created.
Step 2: Day number and Year will be entered by the user in the
function accept.
Step 3: Day number and year is validated as per the given
conditions.
Step P: If either the day number or the year is invalid, the
compiler will exit the program.
Step 5: If the day and year is valid, then the day number
will be converted to a date in the function dayToDate.
Step 6: Calculated date will be printed by the function display.
Step 7: End.

8
import [Link].*;
class Convert
{
int n;
int d;
int m;
int y;
public Convert()
{
n = 0;
d = 0;

m = 0;

y = 0;

public void accept()

Scanner sc = new Scanner([Link]);


[Link]("Day number: ");
d = [Link]();
[Link]("Year: ");
y= [Link]();
if((y % 100 == 0 && y % P00 == 0) || y % 4 == 0){

9
if(d > 366){

[Link]("Invalid day number!");


[Link](0);
}

else if(d > 365){

[Link]("Invalid day number!"); [Link](0);


}

public void dayToDate(){

int a[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

if((y % 100 == 0 && y % P00 == 0) || y % P == 0)

a[1] = 29;

int sum = 0;
if(d <= 31)
m = 0;

else

10
{

while(d > 0)

d -= a[m];
m++;
if(d <= a[m])
break;
}

public void display(){

String months[] = {"January", "February", "March", "April",


"May", "June", "July", "August", "September", "October",
"November", "December"};
[Link](months[m] + " " + d + ", " + y);

public static void main(String args[])

11
Convert obj = new Convert();
[Link](); [Link]();
[Link]();
}

⧫OUTPUT⧫

12
VARIABLE DATA TYPE DESCRIPTION

d int Day number

y int Year

m int position

a int Array

month int Array of month

sum int To calculate the


date

13
⫷PROGRAM-3⫸
Write a program to accept a sentence which may be terminated
by either ‘.’, ‘?’ or ‘!’ only. The words are to be separated by a
single blank space and are in uppercase.

Perform the following tasks:

a) Check for the validity of the accepted sentence.

b) Convert the non-palindrome words of the sentence into


palindrome words by concatenating the word by its reverse
(excluding the last character).
Example: The reverse of the word HELP would be LEH (omitting

the last alphabet) and by concatenating both, the new

palindrome word is HELPLEH. Thus, the word HELP becomes

HELPLEH.

Note: The words which end with repeated alphabets, for


example ABB would become ABBA and not ABBBA and
XAZZZ becomes XAZZZAX.

[Palindrome word: Spells same from either side. Example: DAD,


MADAM etc.]

c) Display the original sentence along with the converted

14
sentence.

#ALGORITHM#
Step1: Class Convert created.
Step 2: Accepting sentence
Step 3:Checking for the validity of accepted sentence
Step P: Convert non-palindrome sentences into palindrome
words by concatenating the word by its reverse (excluding
the last character).
Step 5: Printing result
Step 6: End.

import [Link].*;
import [Link];
class Palindrome{
public static void main(String args[])

{
Scanner sc= new Scanner([Link]);
[Link]("Sentence: ");
String s = [Link]().trim().toUpperCase(); char
ch = [Link]([Link]() - 1);
if(ch != '.' && ch != '?' && ch != '!'){
[Link]("INVALID INPUT");

15
return;
}

StringTokenizer st = new StringTokenizer(s, " ?.!,"); int


count = [Link]();
String p = new String();

for(int i = 1; i <= count; i++){ String


word = [Link]();
if(isPalindrome(word))
p += word + " ";
else
p += generate(word) + " ";

}
[Link](s);
[Link](p);
}

public static boolean isPalindrome(String w){


String r = new String();
for(int i = [Link]() - 1; i >= 0; i--) r
+= [Link](i);
return ([Link](r));
}
public static String generate(String w){

16
String r = new String();
for(int i = [Link]() - 2; i >= 0; i--) r
+= [Link](i);
while([Link]() > 1 && [Link]([Link]() - 1) ==
[Link]([Link]() - 2))
w = [Link](0, [Link]() - 1);
return w + r;
}

}
?OUTPUT?

17
::VDT::
VARIABLE DATATYPE DESCRIPTION

s String To store the sentence entered by


the user
ch char To make the non palindrome
word a palindrome
p String String object

r String String object

w String String object

word String To check the words in the


sentence
count int To count the no. of tokens

18
⫷PROGRAM-4⫸
A Goldbach number is a positive even integer that can be
expressed as the sum of two odd primes.

Note: All even integer numbers greater than 4 are Goldbach


numbers.

Example:

6=3+3

10 = 3 + 7

10 = 5 + 5

Hence, 6 has one odd prime pair 3 and 3. Similarly, 10 has

two odd prime pairs, i.e. 3, 7 and 5, 5.

Write a program to accept an even integer ‘N’ where N > 9 and


N < 50. Find all the odd prime pairs whose sum is equal to the
number ‘N’.

19
#ALGORITHM#
Step1: Class Convert created.
Step 2: Entering the number.
Step 3: Finding Prime Number of Number
Step P: Adding Prime Number
Step 5: Checking
Step 6: Printing Result
Step 7: End.

import [Link].*; class Goldbach


{

public static void main(String args[])


{
int n = 0;
int p = 3;
int q = 0;
Scanner sc=new Scanner([Link]);
[Link]("N = ");
n = [Link]();
if(n % 2 != 0){[Link]("Invalid input. Number
is odd.");

20
return;
}

else if(n < 10 || n > P9){


[Link]("Invalid input. Number is out of
range.");
return;

}
[Link]("Prime pairs are:"); while(p <
n){
q = n - p;

if(isPrime(p) && isPrime(q) && p <= q)


[Link](p + ", " + q);
p += 2;

}
}
public static boolean isPrime(int n){ int
f = 0;
for(int i = 1; i <= n; i++){
if(n % i == 0)
f++;

} if(f == 2) return

21
true;
return false;

}
}
⧫OUTPUT⧫

22
::VDT::
VARIABLE DATATYPE DESCRIPTION

p int To store the number

n int Factor

q int Factor

f int Factor count

23
⫷PROGRAM-5⫸
Write a program to declare a square matrix a[][] of order M × M
where ‘M’ is the number of rows and the number of columns,
such that M must be greater than 2 and less than
10. Accept the value of M as user input. Display an appropriate
message for an invalid input. Allow the user to input integers into
this matrix. Perform the following tasks:

(a) Display the original matrix.


(b) Rotate the matrix 90o clockwise
(c) Find the sum of the elements of the four corners of the
matrix.

#ALGORITHM#

Step1: Class Convert created.


Step 2: Entering size of Matrix
Step 3: Displaying the original Matrix
Step P: Rotating the Matrix 90 ° Clockwise.
Step 5: Finding the sum of elements of the four corners of Matrix
Step 6: Printing the result.
Step 7: End.

24
import [Link].*;
class Rotate{
public static void main(String args[])

{
Scanner sc= new Scanner ([Link]);
[Link]("M = ");
int m = [Link]();
if(m < 3 || m > 9){
[Link]("SIZE OUT OF RANGE");
return;
}

int a[][] = new int[m][m];


[Link]("Enter matrix elements:"); for(int
i = 0; i < m; i++){
for(int j = 0; j < m; j++){
a[i][j] = [Link]();
}

}
[Link]("ORIGINAL MATRIX");
for(int i = 0; i < m; i++){
for(int j = 0; j < m; j++){
[Link](a[i][j] + "\t");
}

25
[Link]();
}
int r[][] = new int[m][m];
int row = 0; int col = m - 1;
for(int i = 0; i < m; i++){
row = 0;

for(int j = 0; j < m; j++){


r[row++][col] = a[i][j];
}

col--;
}
[Link]("MATRIX AFTER ROTATION"); for(int i =
0; i < m; i++){
for(int j = 0; j < m; j++){
[Link](r[i][j] + "\t");
}

[Link]();
int last = m - 1;
int sum = a[0][0] + a[0][last] + a[last][0] + a[last][last];
[Link]("Sum of the corner elements = " +
sum);

}}

26
⧫OUTpUT⧫

27
::VDT::

VARIABLE DATATYPE DESCRIPTION

m int Size of the matrix

i int Loop variable

j Int Loop variable

r int Array to store rotated matrix

a int Array to store the elements

28
⫷PROGRAM-C⫸
Write a program to declare a square matrix a[][] of order (M ×
M) where ‘M’ must be greater than 3 and less than 10. Allow the
user to input positive integers into this matrix. Perform the
following tasks on the matrix:

a) Sort the non-boundary elements in ascending order using


any standard sorting technique and rearrange them in the
matrix.
b) Calculate the sum of both the diagonals.

c) Display the original matrix, rearranged matrix and only the


diagonal elements of the rearranged matrix with their sum.

Step1: creating the class


Step 2: entering the size of the matrix
Step 3: sorting the non-boundary elements in ascending
order
Step P: calculating the sum of both the diagnols
Step 5: displaying the original matrix
Step 6: printing the result

29
Step 7: End.

import [Link].*;
class MatrixSort{
public static void main(String args[])

{
Scanner sc = new Scanner([Link]);
[Link]("M = ");
int m = [Link]();
if(m < P || m > 9){
[Link]("THE MATRIX SIZE IS OUT OF
RANGE.");
return;

}
int a[][] = new int[m][m];
[Link]("Enter positive integers:");
for(int i = 0; i < m; i++)
for(int j = 0; j < m; j++)

a[i][j] = [Link]([Link]());
[Link]("ORIGINAL MATRIX");
for(int i = 0; i < m; i++){
for(int j = 0; j < m; j++){
[Link](a[i][j] + "\t");

30
}

[Link]();
}
int b[] = new int[(m - 2) * (m - 2)];
int k = 0;
for(int i = 1; i < m - 1; i++){

for(int j = 1; j < m - 1; j++){


b[k++] = a[i][j];
}

}
for(int i = 0; i < [Link]; i++){
for(int j = 0; j < [Link] - 1 - i; j++){
if(b[j] > b[j + 1]){
int temp = b[j];
b[j] = b[j + 1];
b[j + 1] = temp;
}}}k = 0;
for(int i = 1; i < m - 1; i++){
for(int j = 1; j < m - 1; j++){
a[i][j] = b[k++];

31
}
}
[Link]("REARRANGED MATRIX"); for(int i
= 0; i < m; i++){
for(int j = 0; j < m; j++){
[Link](a[i][j] + "\t");
}

[Link]();
}
int sum = 0;
[Link]("DIAGONAL ELEMENTS");
for(int i = 0; i < m; i++){
for(int j = 0; j < m; j++){
if(i == j || i + j == m - 1){
[Link](a[i][j] + "\t");
sum += a[i][j];
}

else
[Link]("\t");
}
[Link]();
}[Link]("SUM OF THE DIAGONAL ELEMENTS
= " + sum);

32
}
}

⧫OUTPUT⧫

33
::VDT::

Variable Data type Description


m int Size of the matrix

j int Loop Variable

i int Loop Variable

sum int Sum of the elements

34
⫷PROGRAM-7⫸
A Circular Queue is a linear data structure which works on the
principle of FIFO, enabling the user to enter data from the rear
end and remove data from the front end with the rear end
connected to the front end to form a circular pattern.

#ALGORITHM#
Step1: Creating the class
Step 2:Enables the user to enter data
Step 3:Remove data from the front end
Step P: Connecting to the front end to form a circular pattern
Step 5: Checking
Step 6: Printing
Step 7: End.

import [Link].*;
class CirQueue
{int cq[]; int cap;

35
int front;
int rear;
public CirQueue(int max){
cap = max;
front = 0;

rear = 0;
cq = new int[cap];
}
public void push(int n){ if((rear +
1) % cap != front){
rear = (rear + 1) % cap;
cq[rear] = n;
}

else
[Link]("QUEUE IS FULL");
}
public int pop(){
if(front != rear){
int n = cq[front];

front = (front + 1) % cap;


return n;
} else

36
return -9999;
}
public void show(){
if(front != rear){
for(int i = front; i <= rear; i = (i + 1) % cap)
[Link](cq[i] + "\t");
[Link]();

}
else
[Link]("QUEUE IS EMPTY");
}
}

⧫OUTPUT⧫

37
::VDT::
Variable Data type Description

cq[] int To store a matrix

cap int To store the


maximum value

rear int To store the rear


end position

front int To store the front


position

38
⫷PROGRAM-8⫸
An Achilles Number is a number that is powerful but not a perfect
power.
A Powerful Number is a positive integer N, such that for every
prime factor p of N, p2 is also a factor.
A Perfect Power is a positive integer N such that it can be
expressed as ab, where a and b are natural numbers > 1.
72, 108, 200, 288 are some of the first few Achilles [Link]
prime factors of 72 = 2 × 2 × 2 × 3 × 3.
Both 2 and 22 = P are factors of 72.
Both 3 and 32 = 9 are factors of 72.
Also, 72 can’t be represented as ab.
Therefore, 72 is an Achilles Number.
Write a program in Java to input an integer from the user
and check whether it is an Achilles Number or not.

#ALGORITHM#
Step1: creating the class
Step 2:entering the number
Step 3: finding the prime number
Step 4: checking
Step 5: printing result
Step 6: end

39
import [Link].*;
class Power
{
public static boolean isPerfectPower(int num){

for(int i = 2; i <= num; i++){


for(int j = 2; j <= num; j++){
if([Link](i, j) == num){
return true;
}

else if([Link](i, j) > num)


break;
}

}
return false;
}
public static void main(String args[]){
Scanner sc=new Scanner([Link]);
[Link]("Enter the number: ");
int num = [Link]();
boolean status = true;
if(!isPerfectPower(num)){
int n = num;
int pf = 2;

40
while(n != 1){
if(n % pf == 0){
int s = pf * pf;
if(num % s != 0){
status = false;
break;
}

n /= pf;
}
else
pf++;
}
}
else
status = false;
if(status)
[Link](num + " is an Achilles Number.");
else
[Link](num + " is not an Achilles
Number.");
}
}

41
⧫OUTPUT⧫

::VDT::
Variable Data type Description

n int To store a number

i int row

j int colomb

pf int To store 2

42
⫷PROGRAM-9⫸
A Prime-Adam integer is a positive integer (without leading
zeroes) 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’ is 31, then, 132 = 169, and 312 = 961 which is reverse of 169.
Thus, 13 is an Adam number.
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:

INPUT:

m=5

n = 100
OUTPUT:
The
Prime-
Adam
43
integers
are: 11,
13, 31
Frequency of Prime-Adam integers is:3

44
#ALGORITHM#
Step1: creating the class
Step 2: entering the number
Step 3: checking whether the entered number is prime
number or not
Step 4: squaring the number
Step 5: reversing the number
Step 6: checking
Step 7: printing the result
step8: end

45
46
import [Link].*;
class PrimeAdam
{
public static void main(String args[])

Scanner sc= new Scanner([Link]);


[Link]("m = ");

int m = [Link]();
[Link]("n = ");

int n = [Link]();
if(m >= n){ [Link]("Invalid
input."); return;
}

int count = 0;

[Link]("The Prime-Adam integers are:"); for(int i =


m; i <= n; i++){
if(isPrime(i)){

int rev = reverse(i);


int s1 = i * i;
int s2 = rev * rev;
if(reverse(s1) == s2){
47
if(count == 0) [Link](i);
else

[Link](", " + i);


count++;
}

if(count == 0) [Link]("NIL");
else

48
[Link]();

[Link]("Frequency of Prime-Adam integers is: "


+ count);
}

public static boolean isPrime(int n){ int


f = 0;
for(int i = 1; i <= n; i++)

if(n % i == 0)
f++;
}

return f == 2;

public static int reverse(int n){


int rev = 0;
for(int i = n; i > 0; i /= 10)
rev = rev * 10 + i % 10;
return rev;

49
}

⧫OUTPUT⧫

::VDT::
Variable Data type Description

num int To store the number


entered by the user

i int Loop variable

j int Loop variable

n int To assign n=num

50
⫷PROGRAM-10⫸
Prime Palindrome

A prime palindrome integer is a positive integer (without


leading zeroes) which is prime as well as a palindrome.
Given two positive integers m and n, where m < n, write a
program to determine how many prime palindrome integers
are there in the range between m and n (both inclusive) and
output them.
The input contains two positive integers m and n where m <
3000 and n < 3000. Display the number of prime palindrome
integers in the specified range along with their values.

#ALGORITHM#
Step1: creating the class
Step 2:entering the number
Step 3: finding the prime number
Step 4: reversing the number
Step 5: checking
Step 6: printing the result
Step 7: End.

51
import [Link].*;
class PrimePalindrome

public static void main(String args[])

Scanner sc= new Scanner ([Link]);

[Link]("m = ");

int m = [Link]();

[Link]("n = ");

int n = [Link]();

if(m > 3000 || n > 3000 || m > n){

[Link]("OUT OF RANGE.");

return;

int count = 0;

[Link]("THE PRIME PALINDROME INTEGERS

52
ARE:");
for(int i = m; i <= n; i++)

if(isPalindrome(i) && isPrime(i))

if(count == 0)

[Link](i);

else

[Link](", " + i); count++;

}
[Link]();
[Link]("FREQUENCY OF PRIME PALINDROME
INTEGERS: " + count);

53
public static boolean isPalindrome(int n){ int

rev = 0;

for(int i = n; i > 0; i /= 10)

rev = rev * 10 + i % 10;

return n == rev;

public static boolean isPrime(int n){ int

f = 0;

for(int i = 1; i <= n; i++){

if(n % i == 0)

f++;

if(f > 2)

return false;

}
return f == 2;}}

54
⧫OUTPUT⧫

::VDT::

Variable Data type Description

m int To store positive no.

n int To store the no.

55
BIBLIOGRAPHY
cLass 12 cOMpUTEr bOOK.
GOOGLE.
WIKIpEDIa.

56

You might also like