0% found this document useful (0 votes)
19 views

Computer Project

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Computer Project

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 125

Page |1

Name: Sayed Al Amaan Zaidi


Class: XII
Section: SCI.
Ad. No. : 4753
UID No. : 7863407
School Name: Mount Carmel
Senior Secondary School

Page |2
This is certified that the work reported in this
program report is done by Sayed Al Amaan Zaidi
of class XII.

To the best of my knowledge the report has been


submitted in the presence form the award of any
other examination certificate.

MISS. BABITA SINGH

Page |3
S.NO PROGRAM PAGE NO.
1 EVIL NUMBER 5-9
2 GOLDBACH NUMBER 10-14
3 CARTON PROGRAM 15-20
4 CIRCULAR PRIME 21-27
5 SMALLEST INTEGER AND SUM OF DIGITS 28-35
6 DECODING WORD ACCORDING TO POTENTIAL 36-40
7 DISPLAYING TEAM NAMES IN VERTICAL ORDER IN 41-46
HORIZONTAL TABS

8 CAESER CIPHER INCRIPTION 47-51


9 DISPLACING WORDS AND FINDING VOWELS 48-57
10 FIRST LETTER OF WORD CAPITAL AND FINDING 58-62
NUMBER OF VOWELS AND CONSONANTS

11 FILLING CORNER OF MATRIX BY DIFF. CHARACTERS 63-67


12 SORTING ROW OF MATRIX 68-73
13 RESULT OF QUIZE COMPETITION 74-79
14 SORTING IN ASCENDING ORDER AND SUM OF 80-89
DIAGONALS
15 ROTATING MATRIX 90 DEGREE CLOCKWISE 90-96
16 DATE VALIDATOR 97-102
17 ARRANGING WORDS IN ALPHABETICAL ORDER AND 103-107
SEPERATING WORDS THAT START WITH VOWELS
18 DATE GENERATOR 108-113
19 SORTING MATRIX AND ARRANGIN IN DIFF. FORMAT 114-118
20 NON PALINDROME TO PALINDROME 119-123

Page |4
PROGRAM 1

An Evil number is a posi ve whole number which has even number of 1's in its binary
equivalent. Example: Binary equivalent of 9 is 1001, which contains even number of 1's.
Thus, 9 is an Evil Number.
A few Evil numbers are 3, 5, 6, 9....
Design a program to accept a posi ve whole number 'N' where N>2 and N<100. Find the
binary. equivalent of the number and count the number of Is in it and display whether it is an
Evil number or not with an appropriate message.
Test your program with the following data and some random data:
Example 1:
INPUT: N = 15
BINARY EQUIVALENT: 1111
NUMBER OF 1's: 4
OUTPUT: EVIL NUMBER
Example 2:
INPUT: N = 26
BINARY EQUIVALENT: 11010
NUMBER OF 1's: 3
OUTPUT: NOT AND EVIL NUMBER
Example 3:
INPUT: N = 145
OUTPUT: NUMBER OUT OF RANGE

Page |5
Coding

Page |6
Compiling

Page |7
Outputs

ALGORITHM
Step 1: Start
Step 2: Declare and ini alize variable like ‘Number’, ‘binaryRepresenta on’ , ‘oneCount’, ‘Digit’
Step 3: Display a prompt to the user: "Enter a number (2 < N < 100):"
Step 4: Read the input number from the user.
Step 5: Check if the input number is within the specified range (2 < N < 100).
- If the number is not within the range, display a message: "Please enter a number between 2
and 99."
- If the number is within the range, proceed to the next step.

Page |8
Step 6: Convert the input number to its binary representa on using `Integer.toBinaryString()`
and store it in a string variable (e.g., `binaryRepresenta on`).
Step 7: Ini alize a counter variable `oneCount` to 0 to count the number of '1's in the binary
representa on.
Step 8: Iterate through each character in the `binaryRepresenta on`:
- If the character is '1', increment `oneCount` by 1.
Step 9: Check if the value of `oneCount` is even or odd:
- If it's even, display the message: "The number is an Evil Number."
- If it's odd, display the message: "The number is not an Evil Number."
Step 10: Stop

Variable Description
Variable Name Data type Purpose
Number int Store the user input number to be checked
binaryRepresenta on String Store the binary representa on of the input
number
oneCount int Count the number of ‘1’s in the binary
representa on
Digit char Temporary variable to represent each digit of the
binary string
Scanner Scanner Input Scanner for reading user input

Page |9
PROGRAM 2
A Goldbach number is a posi ve 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 and 7, 5
and 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'.
Test your program with the following data and some random data:
Example 1:
INPUT: N=14
OUTPUT: PRIME PAIRS ARE: 3 , 11
7, 7

Example 2:
INPUT: N=30
OUTPUT: PRIME PAIRS ARE: 7 , 23
11 , 19
13 , 17

Example 3:
INPUT: N=17
OUTPUT: INVALID INPUT. NUMBER IS ODD.
P a g e | 10
Example 4:
INPUT: N = 126
OUTPUT: INVALID INPUT. NUMBER OUT OF RANGE.

CODING

P a g e | 11
COMPILING

P a g e | 12
OUTPUTS

ALGORITHM
Step 1: Start
Step 2: Declare and ini alize variable like ‘found’.
Step 3: Display a prompt to the user: "Enter a posi ve even number greater than 9 and less
than 50:"
Step 4: Read the input number from the user and store it as `number`.
Step 5: Check if `number` is not a valid posi ve even number (less than or equal to 9, greater
than or equal to 50, or not even).
- If the number is invalid, display a message: "Please enter a valid posi ve even number
between 10 and 48."
- If the number is valid, proceed to the next step.

P a g e | 13
Step 6: Ini alize a boolean variable `found` to false. This variable will be used to track if a
Goldbach sum is found.
Step 7: Iterate through odd numbers from 3 to `number / 2` to find two odd primes that sum
up to the input `number`.
- For each odd number `i` in the itera on:
- Check if `i` and `(number - i)` are both prime numbers using the `isPrime` func on.
- If both are prime, display the Goldbach sum: "`number` = `i` + (`number - i`)" and set
`found` to true.
Step 8: If `found` is s ll false a er the itera on, display "No Goldbach sum found for
`number`."
Step 9: Stop

Variable Description
Variable Name Data type Purpose

number int Store the user input to be checked

found boolean Track whether a Goldbach sum has been found

i int Loop variable used to iterate through odd numbers

scanner Scanner Input Scanner for reading user input

P a g e | 14
PROGRAM 3
A company manufactures packing cartons in four sizes, i.e. cartons to accommodate 6 boxes,
12 boxes, 24 boxes and 48 boxes. Design a program to accept the number of boxes to be
packed (N) by the user (maximum up to 1000 boxes) and display the break-up of the cartons
used in descStoping order of capacity (i.e. preference should be given to the highest capacity
available, and if boxes le are less than 6, an extra carton of capacity 6 should be used.)

Test your program with the following data and some random data:

Example 1
INPUT: N=726
OUTPUT: 48 x 15 =720
6x 1 = 6
Remaining boxes = 0
Total number of boxes = 726
Total number of cartons = 16
Example 2
INPUT: N= 140
OUTPUT: 48 x 2 = 96
24 x 1 = 24
12 x 1 = 12
6x1=6
Remaining boxes 2 x 1 = 2
Total number of boxes = 140
Total number of cartons = 6
P a g e | 15
Example 3
INPUT: N=4296
OUTPUT: INVALID INPUT

CODING

P a g e | 16
COMPILING

P a g e | 17
OUTPUTS

ALGORITHM
Step 1: Start
Step 2: Declare and Ini alize variables like ‘totalBoxes’.
Step 3: Prompt the user to enter the number of boxes to be packed (up to 1000 boxes).
Step 4: Read the input number from the user and store it as `totalBoxes`.
Step 5: Check if `totalBoxes` is not within the valid range (less than 0 or greater than 1000).
- If the input is not valid, display "INVALID INPUT" and exit.
- If the input is valid, proceed to the next step.
Step 6: Define an array of carton sizes in descStoping order, e.g., `cartonSizes = {48, 24, 12, 6}`.

P a g e | 18
Step 7: Ini alize `remainingBoxes` as `totalBoxes` to keep track of the remaining boxes.
Step 8: Ini alize `totalCartons` as 0 to keep track of the total number of cartons used.
Step 9: Display "Break-up of cartons used:" to indicate the start of carton break-up informa on.
Step 10: Iterate through each carton size in `cartonSizes`.
- For each carton size:
- Calculate how many cartons of this size can be used (integer division of `remainingBoxes /
size`).
- If `cartonCount` is greater than 0:
- Display the breakdown of cartons used for this size, e.g., "`size` x `cartonCount` = `size *
cartonCount`".
- Update `remainingBoxes` by taking the remainder of `remainingBoxes / size`.
- Update `totalCartons` by adding `cartonCount` to it.
Step 11: Check if there are any remaining boxes (`remainingBoxes > 0`).
- If there are remaining boxes:
- Display the number of remaining boxes, e.g., "Remaining boxes `remainingBoxes` x 1 =
`remainingBoxes`".
- Increment `totalCartons` by 1 to account for the extra carton.
Step 12: If there are no remaining boxes, display "Remaining boxes = 0".
Step 13: Display "Total number of boxes = `totalBoxes`".
Step 14: Display "Total number of cartons = `totalCartons`".
Step 15: Stop.

P a g e | 19
Variable Description
Variable Name Data type Purpose
scanner Scanner Read user input

totalBoxes int Store the number of boxes to pack

cartonSizes int[] Store the available carton sizes

remainingBoxes int Track the number of remaining cartons

totalCartons int Track the number of carton used

size int Represent the current carton size

cartonCount int Store the number of cartons of size

P a g e | 20
PROGRAM 4
A Circular Prime is a prime number that remains prime under cyclic shi s of its digits.
When the le most digit is removed and replaced at the Stop of the remaining string of digits,
the generated number is s ll prime. The process is repeated un l the original number is
reached again.

A number is said to be prime if it has only two factors 1 and itself.

Example: 131
311
113
Hence, 131 is a circular prime.

Accept a posi ve number N and check whether it is a circular prime or not. The new numbers
formed a er the shi ing of the digits should also be displayed.

Test your program with the following data and some random data:

Example 1
INPUT: N=197
OUTPUT: 197
971
719
197 IS A CIRCULAR PRIME

P a g e | 21
Example 2
INPUT: N=1193
OUTPUT: 1193
1931
9311
3119
1193 1S A CIRCULAR PRIME

Example 3
INPUT: N=29
OUTPUT: 29
92
29 IS NOT A CIRCULAR PRIME

P a g e | 22
CODING

P a g e | 23
P a g e | 24
COMPILING

OUTPUTS

P a g e | 25
ALGORITHMS
Algorithm: Check for Circular Prime Number

Step 1: Start

Step2: Declare and initialize variables like ‘number’ , ‘numStr’ , ‘length’.

Step3: Prompt the user to enter a positive number.

Step4: Read the input and store it as number.

Step5: Check if the input number is less than or equal to 1:

- If number <= 1, display "number IS NOT A CIRCULAR PRIME." and stop,


because numbers less than or equal to 1 are not circular primes.

Step6: Check if the number is prime:

- If number == 2, display "number IS A CIRCULAR PRIME.", because 2 is the


smallest prime and also circular.

- If number is even and greater than 2, display "number IS NOT A CIRCULAR


PRIME.", because even numbers greater than 2 are not prime.

- For numbers greater than 2 and odd:

- Check for divisibility by odd numbers starting from 3 up to the square root of
number. If number is divisible by any of these odd numbers, display "number IS NOT
A CIRCULAR PRIME." and stop.

Step7: Convert number to a string and store it as numStr.

Step8: Determine the length of numStr and store it as length.

Step9: Loop through all circular permutations of the number:

- For each permutation:


- Rotate the digits of numStr to the left by one position.
- Convert the rotated string back to an integer.
- Check if the rotated number is prime:
P a g e | 26
- If any rotated number is not prime, display "number IS NOT A CIRCULAR
PRIME." and stop.
- If all circular permutations are prime, display "number IS A CIRCULAR PRIME."

Step 10: Display the circular permutations of the input number to the user. For example,
for 197, the circular permutations would be 197, 971, and 719.

Step 11: Stop.

VARIABLE DESCRIPTION
Variable name Data type Purpose

number int Store the input number.

numStr String Store the input as a string for rota on.

length int Represent the length of the string

P a g e | 27
PROGRAM 5
Given two posi ve numbers M and N, such that M is between 100 and 10000 and N is less
than 100. Find the smallest integer that is greater than M and whose digits add up to N. For
example, if M = 100 and N = 11, then the smallest integer greater than 100 whose digits add
upto 11s 119.

Write a program to accept the numbers M and N from the user and print the smallest required
number whose sum of all its digits is equal to N. Also, print the total number of digits present
in the required number. The program should check for the validity of the inputs and display an
appropriate message for an invalid input.

Test your program with the sample data and some random data:

Example 1
INPUT: M= 100
N=11
OUTPUT: The required number = 119
Total number of digits = 3
Example 2
INPUT: M= 1500
N=25
OUTPUT: The required number = 1699
Total number of digits = 4
Example 3
INPUT: M=99
P a g e | 28
N=11
OUTPUT: INVALID INPUT
Example 4
INPUT: M=112
N=130
OUTPUT: INVALID INPUT

CODING

P a g e | 29
COMPILING

P a g e | 30
OUTPUTS

ALGORITHM
Step 1: Start

Step 2: Declare and initialize variables like ‘M’, ‘N’.

Step 3: Prompt the user to enter a positive number M between 100 and 10,000.

Step 4: Read the input and store it as M.

Step 5: Prompt the user to enter a number N less than 100.

Step 6: Read the input and store it as N.

Step 7: Check for the validity of the inputs:

- If M is less than 100 or greater than 10,000, or N is greater than or equal to 100:
P a g e | 31
- Display "INVALID INPUT" and stop the program.

Step 8: Find the smallest integer greater than M whose digits add up to N:

- Initialize a loop:
- Increment M by 1 in each iteration.
- Calculate the sum of the digits of M.
- If the sum of the digits equals N, break the loop and proceed.

Step 9: Calculate the total number of digits in the required number:

- Initialize a counter count to 0.


- While M is not 0:
- Increment count by 1.
- Remove the last digit from M by integer division.

Step 10: Display the required number (smallest integer greater than the original M whose
digits sum up to N) and the total number of digits.

Step 11: Stop.

VARIABLE DESCRIPTION
Variable Data Purpose
name type
M int Store the user input posi ve number (between 100
and 10,000)
N int Store the user-input number(less than 100)
M int Represents the input posi ve number.
N int Represents the input number.
number int Represents the input number for the digit sum
calcula on
sum int Stores the sum of digitss
number int Represents the input number for digit coun ng
count int Store the count of digits.

P a g e | 32
PROGRAM 6
The potential of a word is found by adding the ASCII value of the alphabets. (ASCII values of A
to Z are 65 to 90). Example: BALL Potential 66+65 +76+76=283 Write a program to accept a
sentence which may be terminated by either ".", "?" or "!" only. The words of sentence are
separated by single blank space and are in UPPER CASE. Decode the words according to their
potential and arrange them in ascStoping order of their potential strength. Test your program
with the following data and some random data: Example 1: INPUT: HOW DO YOU DO?
OUTPUT: HOW = 238
DO = 147
YOU = 253
DO = 147

Example 2:
INPUT: LOOK BEFORE YOU LEAP.
OUTPUT: LOOK = 309
BEFORE = 435
YOU= 253
LEAP=290

Example 3:
INPUT: HOW ARE YOU#
OUTPUT: INVALID INPUT

P a g e | 33
CODING

P a g e | 34
COMPILING

P a g e | 35
OUTPUTS

ALGORITHMS
Step 1: Start

Step 2: Declare and initialize variables like ‘inputSentence’, ‘words’.

Step 3: Prompt the user to input a sentence (terminated by '.', '?', or '!').

Step 4: Read and store the input sentence as inputSentence.

Step 5: Check for input validity:

- If inputSentence does not end with '.', '?', or '!', display "INVALID INPUT" and
stop the program.
- Otherwise, proceed to the next step.

Step 6: Remove punctuation marks ('.', '?', and '!') from inputSentence by replacing them with
an empty character.

P a g e | 36
Step 7: Split the sentence into words and store them in an array called words.

Step 8: Create an array potentialWords to store each word along with its potential.

Step 9: For each word in words, calculate its potential:

- Initialize the potential to 0.


- For each character in the word, convert the character to its ASCII value and
add it to the potential.
- Store the word and its potential in the potentialWords array.

Step 10: Sort the potentialWords array in ascending order based on the potential values.

Step 11: Display the sorted words along with their potential values in the following format:

- For each word in potentialWords, display the word followed by its potential
value.

Step 12: Stop.

VARIABLE DESCRIPTION
Variable name Data type Purpose
inputSentence String Store the user-input sentence.
words String[] Store the words split from ‘inputSentence’.
poten alWords Poten alWord[] Store words and their poten als.
word String Store the word for poten al calcula on.
poten al int Store the calculated poten al of the word.
input String Store the input sentence foe validity check.

P a g e | 37
PROGRAM 7
The names of the teams par cipa ng in a compe on should be displayed on a
banner ver cally, to accommodate, as many teams as possible in a single banner.
Design a program to accept the names of N teams, where 2 < N < 9 and display
them in ver cal order, side by side with a horizontal tab (i.e. eight spaces).

“Test your program for the following data and some random data

Example 1:
INPUT: N=3
Team I: Emus
Team 2: Road Rols
Team 3: Coyote
OUTPUT:
E R C
m o o
u a y
s d o
t
R e
o
l
s
Example 2:
INPUT: N=4
P a g e | 38
Team 1: Royal
Team 2: Mars
Team 3: De Rose

Team 4: Kings
OUTPUT:
R M D K
o a e i
y r n
a s R g
l o s
s
e
Example 3:
INPUT: N=10
OUTPUT: INVALID INPUT

P a g e | 39
Coding

P a g e | 40
COMPILING

OUTPUTS

P a g e | 41
ALGORITHMS
Step 1: Start

Step 2: Declare and initialize variables like ‘N’, ‘teams’, ‘maxLength’.

Step 3: Prompt the user to input the number of teams N (where 2 < N < 9).

Step 4: Read and store the input as N.

Step 5: Check for input validity:

- If N is less than 3 or greater than 8, display "INVALID INPUT" and stop the
program.
- Otherwise, proceed to the next step.

Step 6: Create an array teams of size N to store the team names.

Step 7: Consume the newline character left in the input buffer by calling scanner.nextLine().

Step 8: For each team (from 1 to N), do the following:

- Prompt the user to input the name of Team i.


- Read and store the input as teams[i-1].

Step 9: Find the maximum length (maxLength) among all the team names in the teams array:

- Initialize maxLength to 0.
- For each team name in teams, if the length of the team name is greater than
maxLength, set maxLength to the length of that team name.

Step 10: Display the teams vertically by iterating over each character position from 0 to
maxLength - 1:

- For each character index i from 0 to maxLength - 1:


- For each team name in teams, check if the character at index i exists in the
team name:
- If the character exists, print the character followed by a horizontal tab (\t).
- If the character does not exist (i.e., the team name is shorter), print a
horizontal tab (\t).

P a g e | 42
Step 11: After printing all the characters for the current row, print a newline character to start
a new row.

Step 12: Repeat this process until all the characters from all the team names have been
printed vertically.

Step 13: Stop.

VARIABLE DESCRIPTION
Variable name Data type Purpose
scannner Scanner Create a Scanner object for user input.
N int Store the number of teams.
teams String[] Store the names of teams.
maxLength int Store the maximum length among team names.
i int Loop counter for index.
J int Loop counter for characters within names.
i int Loop counter for index.
maxLength Int Store the maximum length among team names.
j int Loop counter for characters within names.

P a g e | 43
PROGRAM 8
Caesar Cipher is an encryp on technique which is implemented as ROTI3 (‘rotate by
13places”). I s a simple le er subs tu on cipher that replaces a le er with the le er 13 places
a er it in the alphabets, with the other characters remaining unchanged.
Write a program to accept a plain text of length L, where L must be greater than 3 and less
than 100.
Encrypt the text if valid as per the Caesar Cipher.
Test your program with the sample data and some random data:
Example 1
INPUT: Hello! How are you?
OUTPUT: The cipher text is: Uryyb? Ubj ner Ibh?
Example 2
Input: Encryp on helps to secure data.
Output: The cipher text is : Rapelcgvba Urycf gb frpher gngn.
Example 3
Input: You
Output: Invalid Length.

P a g e | 44
CODING

P a g e | 45
COMPILING

P a g e | 46
OUTPUTS

ALGORITHMS
Step 1: Start.

Step 2: Declare and initialize variables like ‘chars’, ‘c’, ‘base’.

Step 3: Prompt the user to enter a plain text, ensuring its length is between 4 and 99
characters.

Step 4: Read and store the input as plainText.

Step 5: Check for input validity:

- If the length of plainText is less than 4 or greater than or equal to 100, display
"Invalid Length" and stop the program.
- Otherwise, proceed to the next step.

P a g e | 47
Step 6: Encrypt the plainText using the Caesar Cipher ROT13 transformation as follows:

- Convert plainText into a character array chars.


- For each character c at index i in chars:
- Check if c is a letter (either lowercase or uppercase).
- If it is a letter, determine whether it is lowercase or uppercase:
- Set the base character as 'a' for lowercase letters and 'A' for uppercase letters.
- Apply the Caesar Cipher ROT13 transformation by shifting the character c by
13 positions forward:
- Add 13 to the ASCII value of c, relative to its base character.
- Use modulo 26 to ensure the character wraps around if it goes past 'z' or 'Z'.
- Replace the character at index i in chars with the new shifted character.

Step 7: Convert the modified character array chars back into a string and store it as the
encrypted cipher text.

Step 8: Display the encrypted cipher text.

Step 9: Stop.

VARIABLE DESCRIPTION
Variable name Data type Purpose
chars char[] Store the characters of the ‘plaintext’.
i int Loop counter for character index in ‘chars’.
c char Store the character at index ‘i’ in ‘chars’.
base char Determine the base character(‘a’ or ‘A’).
newChar char Store the new character a er encryp on.
scanner Scanner Create a Scanner object for user input.
plainText String Store the plain text entered by the user.
cipherText String Store the encrypted text(Caesar Cipher result).

P a g e | 48
PROGRAM 9
Write a program to accept a sentence which may be terminated by “.” only.
The words may be separated by more than one blank space and are in UPPER CASE.
Perform the following tasks:
(a) Find the number of words beginning and Stoping with a vowel.
(b) Place the words which begin and Stop with a vowel at the beginning, followed by the
remaining words as they occur in the sentence.
Test your program with the sample data and some random data:
Example 1
INPUT:ANAMIKA AND SUSAN ARE NEVER GOING TO QUARREL
ANYMORE.
OUTPUT: NUMBER OF WORDS BEGINNING AND STOPING WITH A VOWEL =3
ANAMIKA ARE ANYMORE AND SUSAN NEVER GOING TO QUARREL.

Example 2
INPUT: YOU MUST AIM TO BE A BETTER PERSON TOMORROW THAN YOU
ARE TODAY.
OUTPUT: NUMBER OF WORDS BEGINNING AND STOPING WITH A VOWEL =2
A ARE YOU MUST AIM TO BE BETTER PERSON TOMORROW
THAN YOU TODAY

Example 3
INPUT: LOOK BEFORE YOU LEAP.
OUTPUT: NUMBER OF WORDS BEGINNING AND STOPING WITH A VOWEL = 0
LOOK BEFORE YOU LEAP.
P a g e | 49
Example 4
INPUT: HOW ARE YOU@
OUTPUT: INVALID INPUT

CODING

P a g e | 50
COMPILING

P a g e | 51
OUTPUTS

ALGORITHMS
Step 1: Start.

Step 2: Declare and initialize variables like ‘input’, ‘words’, ‘vowelWordCount’.

Step 3: Prompt the user to enter a sentence and store it as input.

Step 4: Check if the input sentence ends with one of the following: "*.", or "1":

- If it does, proceed to the next steps.


- If not, display "INVALID INPUT" and stop the program.

Step 5: Split the input sentence into individual words using whitespace as the delimiter and
store them in an array words.

Step 6: Initialize the following variables:

P a g e | 52
- vowelWordsCount to keep track of the number of words that begin and end
with a vowel (initially set to 0).
- vowelWords to store the words that start and end with a vowel.
- remainingWords to store the words that do not start and end with a vowel.

Step 7: Iterate through each word in the words array:

- Check if the word begins and ends with a vowel using the following steps:
- Check if the length of the word is greater than or equal to 2:
- If it's not, return false since it cannot be a valid word.
- If it is, proceed to the next step.
- Extract the first character (firstChar) and the last character (lastChar) of the
word.
- Check if both firstChar and lastChar are vowels by converting them to
uppercase and checking if they equal 'A', 'E', 'I', 'O', or 'U':
- If both are vowels, return true.
- If not, return false.
- If the word does begin and end with a vowel:
- Increment vowelWordsCount.
- Append the word to the vowelWords with a space.
- If the word does not begin and end with a vowel:
- Append the word to the remainingWords with a space.

Step 8: Display the count of words beginning and ending with a vowel (vowelWordsCount).

Step 9: Display the vowelWords, followed by a space, and then the remainingWords.

Step 10: Stop.

P a g e | 53
VARIABLE DESCRIPTION
Variable name Data type Purpose
scanner Scanner Create a Scanner object for user input.
input String Store the input sentence.
words String[] Store the words from the input sentence.
vowelWordsCount int Count the words beginning and Stoping with a vowel.

vowelWords StringBuilder Store vowel words.


remainingWords StringBuilder Store non-vowel words.
word String A single word from the ‘words’ array
word String A word to check if it begins and Stops with a vowel.

firstChar char The first character of the ‘word’


lastChar char The last character of the ‘word’
c char The character to check if it’s a vowel

P a g e | 54
PROGRAM 10

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. Print an error message if the input does not
terminate with '.' or "?". You can assume that no word in the sentence exceeds 15 characters,
so that you get a proper formatted output. Perform the following tasks: (i)Convert the first
letter of each word to uppercase. (ii) Find the number of vowels and consonants in each word
and display them with proper headings along with the words. Test your program with the
following inputs.

Example 1
INPUT: Intelligence plus character is education.
OUTPUT: Word Vowels Consonants

Intelligence 5 7
Plus 1 3
Character 3 6
Is 1 1
Education 5 4

Example 2
INPUT: All the best!
OUTPUT: Invalid Input.

P a g e | 55
CODING

P a g e | 56
COMPILING

OUTPUTS

P a g e | 57
ALGORITHMS
Step 1: Start.

Step 2: Declare and initialize variables like ‘input’ , ‘words’.

Step 3: Prompt the user to enter a sentence terminated by '.' or '?' and store it as input.

Step 4: Check if the input ends with '.' or '?':

- If it does, proceed to the next steps.


- If not, display "Invalid Input" and stop the program.

Step 5: Display the headers for the output: "Word Vowels Consonants".

Step 6: Split the input sentence into words using whitespace as the delimiter and store them
in an array words.

Step 7: For each word in the words array, do the following:

- Convert the first letter of the word to uppercase.


- Count the number of vowels and consonants in the word using the following
steps:
- Initialize a count variable to 0.
- Iterate through each character c in the word:
- Check if c is one of 'A', 'E', 'I', 'O', 'U' (uppercase):
- If it is, increment the count by 1.
- Return the count of vowels.
- Calculate the number of consonants in the word by subtracting the count of
vowels from the length of the word.
- Display the word, the count of vowels, and the count of consonants in a
formatted manner.

Step 8: Stop.

P a g e | 58
VARIABLE DESCRIPTION
Variable name Data type Purpose
scanner Scanner Create a Scanner object for user input.
input String Store the input sentence
words String[] Store the words from the input sentence
word String A single word from the ‘words’ array.
word String A word to count vowels in.
count int Count the number of vowels.
c char A character in the ‘word’.

P a g e | 59
PROGRAM 11
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:

(i)Fill the four corners of the square matrix by character 1.

(ii)Fill the boundary elements of the matrix (except the four corners) by character 2.

(iii)Fill the non-boundary elements of the matrix by character 3.

Test your program with the following data and some random data:
Example 1:
INPUT: N=4
FIRST CHARACTER: @
SECOND CHARACTER: ?
THIRD CHARACTER: #

OUTPUT:
@ ? ? @
? # # ?
? # # ?
@ ? ? @

Example 2:
INPUT: N=5
FIRST CHARACTER: A
SECOND CHARACTER: C
THIRD CHARACTER: X

OUTPUT:
A C C C A
C X X X C
C X X X C
A C C C A

Example 3:
INPUT: N = 12
P a g e | 60
OUTPUT: SIZE OUT OF RANGE

CODING

P a g e | 61
COMPILING

P a g e | 62
OUTPUTS

ALGORITHMS
Step 1: Start.
Step 2: Decalre and ini alize variables like ‘N’, ‘char1’, ‘char2, ‘ char3’.
Step 3: Prompt the user to enter the order of the square matrix 'N' and store the input in the
`N` variable.
Step 4: Check if `N` is within the valid range (between 4 and 9):
- If it's valid, proceed to the next steps.
- If not, display "SIZE OUT OF RANGE" and Stop the program.

Step 5: Prompt the user to enter the first character and store it in the `char1` variable.
Step 6: Prompt the user to enter the second character and store it in the `char2` variable.
Step 7: Prompt the user to enter the third character and store it in the `char3` variable.
Step 8: Create a 2D character array `M` of size `NxN`.

P a g e | 63
Step 9: Iterate through the rows `i` from 0 to `N-1` and columns `j` from 0 to `N-1`:
- Check if `i` is 0 and `j` is either 0 or `N-1`, or if `i` is `N-1` and `j` is either 0 or `N-1`:
- If true, set `M[i][j]` to `char1`.
- Check if `i` is 0, `i` is `N-1`, `j` is 0, or `j` is `N-1`:
- If true, set `M[i][j]` to `char2`.
- Otherwise, set `M[i][j]` to `char3`.
Step 10: Display the filled square matrix by itera ng through rows and columns.
Step 11: Stop.

VARIABLE DESCRIPTION
Variable name Data type Purpose
scanner Scanner Create a Scanner object for user input.
N int Store the order of the square matrix.
char1 char Store the first character input.
char2 char Store the second character input.
char3 char Store the third character input.
M char[][] Create a 2D character array for the square matrix.

P a g e | 64
PROGRAM 12
Write a program to declare a matrix A[][] of order (MXN) where 'M' is the number of rows and
'N' is the number of columns such that the values of both 'M' and 'N' must be greater than 2
and less than 10. Allow the user to input integers into this matrix. Perform the following tasks
on the matrix:
(a) Display the original matrix.
(b) Sort each row of the matrix in ascending order using any standard sor ng technique. (c)
Display the changed matrix a er sor ng each row.
Test your program for the following data and some random data:
Example 1:
INPUT: M=4 N=3
ENTER ELEMENTS OF MATRIX
11 -2 3
5 16 7
9 0 4
3 1 8

OUTPUT:
ORIGINAL MATRIX
11 -2 3
5 16 7
9 0 4
3 1 8
MATRIX AFTER SORTING ROWS
-2 3 11
5 7 16

P a g e | 65
0 4 9
1 3 8
Example 2:
INPUT: M=3 N=3
ENTER ELEMENTS OF MATRIX
22 5 19
7 36 12
9 13 6

OUTPUT:
ORIGINAL MATRIX
22 5 19
7 36 12
9 13 6

MATRIX AFTER SORTING ROWS


5 19 22
7 12 36
6 9 13

Example 3:
INPUT: M=11 N=5
OUTPUT:
MATRIX SIZE OUT OF RANGE

P a g e | 66
CODING

P a g e | 67
COMPILING

OUTPUTS

P a g e | 68
ALGORITHMS
Step 1: Start.
Step 2: Declare and initialize variables like ‘M’, ‘N’.
Step 3: Prompt the user to enter the number of rows (M) and store the input in the variable
`M`.
Step 4: Prompt the user to enter the number of columns (N) and store the input in the variable
`N`.
Step 5: Check if both `M` and `N` are greater than 2 and less than 10:
- If they are, proceed to the next steps.
- If not, display "MATRIX SIZE OUT OF RANGE" and Stop the program.
Step 6: Create a 2D integer array `A` with dimensions MxN.

P a g e | 69
Step 7: Display a message to enter the elements of the matrix.
Step 8: Iterate through the rows (i) from 0 to M-1 and columns (j) from 0 to N-1:
- Prompt the user to enter an integer and store it in `A[i][j]`.
Step 9: Display "ORIGINAL MATRIX" and call the `displayMatrix` func on to display the
contents of matrix A.
Step 10: Iterate through each row (i) from 0 to M-1:
- Sort the elements in the row `A[i]` in ascStoping order.
Step 11: Display "MATRIX AFTER SORTING ROWS" and call the `displayMatrix` func on to
display the sorted matrix A.
Step 12: Stop.

VARIABLE DESCRIPTION
Variable name Data type Purpose
scanner Scanner Create a Scanner object for user input.
M int Store the number of rows in the matrix.
N int Store the number of columns in the matrix.
A int[][] Create a 2D integer array for the matrix.
i int Loop variables for rows.
j int Loop variable for columns.

P a g e | 70
PROGRAM 13
The result of a quiz compe on is to be prepared as follows: The quiz has five PROGRAMs with
four mul ple choices (A, B, C, D), with each PROGRAM carrying 1 mark for the correct answer.
Design a program to accept the number of par cipants N such that N must be greater than 3
and less than 11. Create a double dimensional array of size (Nx5) to store the answers of each
par cipant row-wise. Calculate the marks for each par cipant by matching the correct answer
stored in a single dimensional array of size 5. Display the scores for each par cipant and also
the par cipant(s) having the highest score.
Test your program for the following data and some random data:
Example 1
INPUT: N=5
Par cipant 1 D A B C C
Par cipant 2 A A D C B
Par cipant 3 B A C D B
Par cipant 4 D A D C B
Par cipant 5 B C A D D
Key: B C D A A
OUTPUT:
Scores:
Par cipant 1 = 0
Par cipant 2 = 1
Par cipant 3 = 1
Par cipant 4 = 1
Par cipant 5 = 2
Highest score: Par cipant 5

P a g e | 71
Example 2
INPUT: N=12
OUTPUT : SIZE OUT OF RANGE

CODING

P a g e | 72
P a g e | 73
COMPILING

P a g e | 74
OUTPUTS

ALGORITHMS
Step 1: Start.
Step 2: Declare and ini alize variable like ‘N’, ‘answers’.
Step 3: Prompt the user to enter the number of par cipants (N) and store the input in the
variable `N`.
Step 4: Check if N is greater than 3 and less than 11:
- If it is, proceed to the next steps.
- If not, display "SIZE OUT OF RANGE" and Stop the program.
Step 5: Create a 2D char array `answers` of size (Nx5) to store the answers of each par cipant.
Ini alize it with empty characters.
Step 6: Display a message to enter the answers for each par cipant:
- Iterate through each par cipant (i) from 0 to N-1.
P a g e | 75
- For each par cipant, iterate through the answers (j) from 0 to 4.
- Prompt the user to enter an answer and store it in `answers[i][j]`.

Step 7: Create a 1D char array `key` with the correct answers for each PROGRAM.
Step 8: Create a 1D int array `scores` of size N to store the scores for each par cipant.
Step 9: Calculate the scores for each par cipant:
- Iterate through each par cipant (i) from 0 to N-1.
- For each par cipant, iterate through the answers (j) from 0 to 4.
- Compare the answer in `answers[i][j]` with the correct answer in `key[j]`:
- If they match, increment the par cipant's score in `scores[i]`.
Step 10: Display "Scores" and the scores for each par cipant:
- Iterate through each par cipant (i) from 0 to N-1.
- Display "Par cipant (i + 1) = scores[i]".
Step 11: Find the highest score among all par cipants:
- Ini alize a variable `highestScore` to 0.
- Iterate through each par cipant's score (score) in `scores`:
- If `score` is greater than `highestScore`, update `highestScore` with the new highest score.
Step 12: Display "Highest score" and the par cipant(s) with the highest score:
- Iterate through each par cipant (i) from 0 to N-1.
- If the score of the par cipant matches `highestScore`, display "Par cipant (i + 1)".
Step 13: Stop.

P a g e | 76
VARIABLE DESCRIPTION
Variable Data Purpose
name type
scanner Scanner Create a Scanner object for user input.
N int Store the number of par cipants.
answers char[][] Create a 2D char array to store par cipant answers.

key char[] Create a 1D char array to store the correct answers.

scores int[] Create a 1D int array to store the par cipant scores.

P a g e | 77
PROGRAM 14
Write a program to declare a square matrix A[][] of order (MxM) where 'M' must be greater
than 3 and less than 10. Allow the user to input posi ve integers into this matrix. Perform the
following tasks on the matrix:
(a) Sort the non-boundary elements in Ascending order using any standard sor ng 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.
Test your program for the following data and some random data:

Example 1
INPUT:
M=4
9 2 1 5
8 13 8 4
15 6 3 11
7 12 23 8
OUTPUT:
ORIGINAL MATRIX
9 2 1 5
8 13 8 4
15 6 3 11
7 12 23 8

P a g e | 78
REARRANGED MATRIX
9 2 1 5
8 3 6 4
15 8 13 11
7 12 23 8

DIAGONAL ELEMENTS
9 0 0 5
0 3 6 0
0 8 13 0
7 0 0 8

SUM OF THE DIAGONAL ELEMENTS = 59

Example 2:
INPUT:
M=5
7 4 1 9 5
8 2 6 10 19
13 1 3 5 1
10 0 5 12 16
1 8 17 6 8

P a g e | 79
OUTPUT:
ORIGINAL MATRIX
7 4 1 9 5
8 2 6 10 19
13 1 3 5 1
10 0 5 12 16
1 8 17 6 8

REARRANGED MATRIX
7 4 1 9 5
8 0 1 2 19
13 3 5 5 1
10 6 10 12 16
1 8 17 6 8

DIAGONAL ELEMENTS
7 0 0 0 5
0 0 0 2 0
0 0 5 0 0
0 6 0 12 0
1 0 0 0 8

Example 3
INPUT: M=3
OUTPUT: THE MATRIX SIZE IS OUT OF RANGE.

P a g e | 80
CODING

P a g e | 81
P a g e | 82
COMPILING

OUTPUTS

P a g e | 83
P a g e | 84
ALGORITHMS
Step 1: Start
Step 2: Declare and ini alize variable ‘M’.
Step 3: Prompt the user to enter the size of the square matrix (M).
Step 4: Read and store the value of M.
Step 5: If M is greater than 3 and less than 10, con nue; otherwise, display an error message
and terminate.
Step 6: Declare a 2D integer array `matrix` of size M x M.
Step 7: Prompt the user to enter posi ve integers into the matrix and populate the `matrix`
with user inputs.
Step 8: Display the original matrix (`matrix`) to the user.
Step 9: Call the `rearrangeMatrix` func on to sort and rearrange the non-boundary elements
of the matrix.
- Iterate through the matrix elements except the boundary elements (from row 1 to M-2 and
from column 1 to M-2).
- Store these non-boundary elements in a 1D array.
- Sort the 1D array.
- Replace the non-boundary elements in the matrix with the sorted values.
Step 10: Display the rearranged matrix.
Step 11: Call the `extractDiagonalElements` func on to extract diagonal elements from the
rearranged matrix.
- Create a new 2D array to store the diagonal elements.
- Iterate through the matrix elements and copy the diagonal elements to the new array.
Step 12: Display the diagonal elements.
Step 13: Call the `calculateSumOfDiagonal` func on to calculate the sum of the diagonal
elements.
- Ini alize a sum variable to zero.
- Iterate through the diagonal elements in the new array and add them to the sum.
P a g e | 85
- If the matrix size is odd, subtract the center element from the sum to avoid double-
coun ng.
Step 14: Display the sum of the diagonal elements.
Step 15: Stop.

VARIABLE DESCRIPTION
Variable name Data type Purpose

M int Stores the size of the square matrix (M.)


matrix int[][] Stores the original square matrix.
diagonalArray Int[] Stores the diagonal elements from the rearranged
matrix.

sum Int Store the sum of diagonal elements.

P a g e | 86
PROGRAM 15
Write a program to declare a square matrix A[ ][ ] of order MxM 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 90° clockwise as shown below:

(c) Find the sum of the elements of the four comers of the matrix.
Test your program with the sample data and some random data:

Example 1
INPUT: M=3
3 4 9
2 5 8
1 6 7
OUTPUT :
ORIGINAL MATRIX
3 4 9
2 5 8
1 6 7

P a g e | 87
MATRIX AFTER ROTATION
1 2 3
6 5 4
7 8 9
Sum of the corner elements =20

Example 2
INPUT: M=4
1 2 4 9
2 5 8 3
1 6 7 4
3 7 6 5
OUTPUT :
ORIGINAL MATRIX
1 2 4 9
2 5 8 3
1 6 7 4
3 7 6 5

MATRIX AFTER ROTATION


3 1 2 1
7 6 5 2
6 7 8 4
5 4 3 9
Sum of the corner elements = 18
Example 3

P a g e | 88
INPUT: M=14
OUTPUT: SIZE OUT OF RANGE

CODING

P a g e | 89
P a g e | 90
P a g e | 91
COMPILING

OUTPUTS

P a g e | 92
ALGORITHM
Step 1: Import the `Scanner` class.
Step 2: Declare and ini alize variable `M`.
Step 3: Prompt the user to enter the size of the square matrix (M).
Step 4: Read and store the value of `M`.
Step 5: If `M` is less than or equal to 2 or greater than or equal to 10, display "SIZE OUT OF
RANGE" and terminate the program.
Step 6: Declare a 2D integer array `matrix` of size M x M.
Step 7: Prompt the user to enter integers into the matrix and populate the `matrix` with user
inputs.
Step 8: Display the original matrix (`matrix`) to the user.
Step 9: Rotate the matrix 90° clockwise using the `rotateMatrixClockwise` func on.

P a g e | 93
Step 10: Display the rotated matrix.
Step 11: Calculate and display the sum of the elements of the four corners of the matrix using
the `sumOfCornerElements` func on.
Step 12: Stop.

VARIABLE DESCRIPTION
Variable Name Data type Purpose

M int Stores the size of square matrix

matrix int[][] Stores the square matrix

sumOfCorners int Stores the sum of corner elements

P a g e | 94
PROGRAM 16
Design a program which inputs a date in six digit number format i.e. 141296. Test the validity
of the
date and print the date in full form . If date is invalid then print a message as * Invalid Date*

1. Example :
INPUT: 141296
OUTPUT : 14 December, 96
VALID DATE
2. Example :
INPUT: 230488
OUTPUT : 23 April, 88
VALID DATE

3. Example
INPUT : 300284
OUTPUT: 30 February, 84
VALID DATE

P a g e | 95
CODING

P a g e | 96
COMPILING

There is a compiling error I have declared “month” variable but in argument given “mounth” which is not declared.

So it gives the error that it cannot find that variable

To Solve it change the argument variable name to the declared variable

P a g e | 97
Done now it has compiled without any errors.

P a g e | 98
OUTPUTS

ALGORITHM
Step 1: Import the `Scanner` class.
Step 2: Declare and ini alize a variable `date`.
Step 3: Prompt the user to enter a six-digit date.
Step 4: Read and store the value of `date`.
Step 5: Extract day, month, and year from the six-digit date.
Step 6: Check the validity of the date:
- If the day is between 1 and 31 and the month is between 1 and 12, the date is valid.
- Otherwise, print "INVALID DATE" and introduce a compiling error in the program.
Step 7: Display the date in full form (day, month, year).
Step 8: Stop.

P a g e | 99
VARIABLE DESCRIPTION
Variable name Data type Purpose
scanner Scanner To read input from the user.
date int To store the six-digit date input.
day int To store the extracted day from the date
month int To store the extracted month from the date
year int To store the extracted year from the date.

P a g e | 100
PROGRAM 17
Accept a paragraph of text consis ng of sentences that are terminated by either "." , "!"or a "?"

followed by a space. Assume that there can be a maximum of 05 sentences in a paragraph.

Design a program to perform the following :

(a) Arrange the sentences in alphabe cal order of words, sentence by sentence.

(b) Separate the words which begin with a vowel.

Sample data 1:

INPUT: HELLO ! HOW ARE YOU ? WHEN ARE YOU COMING ? HOPE TO SEE YOU

SOON.

OUTPUT: HELLO ! ARE HOW YOU ? ARE COMING WHEN YOU ? HOPE SEE SOON

TO YOU.

VOWELS: ARE ARE

Sample data 2

INPUT : THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.

OUTPUT: BROWN DOG. FOX JUMPED LAZY OVER QUICK THE THE.

VOWELS: A OVER

P a g e | 101
CODING

P a g e | 102
COMPILING

There is an error because I have not assigned any variable named scan but I have assigned scanner that is the object of
Scanner class

So to solve it just change the scan to scanner.

P a g e | 103
Done no compiling errors now.

OUTPUTS

ALGORITHM
Step 1: Start
Step 2: Declare and ini alize variable like ‘paragraphInput’, ‘sentences’.
Step 3: Process paragraph.
- Split the paragraph into sentences using the regular expression "[.!?]\\s".

- For each sentence:


- Split the sentence into words using the regular expression "\\s".
- Sort the array of words alphabe cally.
- Join the sorted words to form the modified sentence.

P a g e | 104
- Output the arranged sentences by joining them with spaces.

Step 4: Extract Vowels


- Ini alize an empty StringBuilder to store words star ng with vowels.

- For each sentence:


- Split the sentence into words using the regular expression "\\s".
- For each word:
- Check if the word starts with a vowel using the regular expression "[AEIOUaeiou][a-zA-
Z]*".
- If yes, appStop the word to the StringBuilder.

- Output the vowels by conver ng the StringBuilder to a string.

Step 5: Stop

VARIABLE DESCRIPTION
Variable Name Data Purpose
type
paragraphInput String Stores the user input paragraph.
sentences String[] To split the paragraph into sentence.
words String[] To split each sentence into words.
vowelWords StringBuild To collect and concatenate words star ng with vowels.
er

P a g e | 105
PROGRAM 18
Design a program to accept a day number (between 1 and 366). year (in 4 digits) from the user
to generate and display the corresponding date. Also, accept “N” (1 <= N <= 100) from the
user to compute and display the future date corresponding to “N” days a er the generated
date.
Display an error message if the value of the day number, year and N are not within the limit or
not according to the condi on specified.

Test your program with the following data and some random data:

Example 1
INPUT: DAY NUMBER: 255
YEAR: 2018
DATE AFTER (N DAYS): 22
OUTPUT: DATE: 12TH SEPTEMBER, 2018
DATE AFTER 22 DAYS: 4TH OCTOBER, 2018
Example 2
INPUT: DAY NUMBER: 360
YEAR: 2018
DATE AFTER (NDAYS): 45
OUTPUT: DATE: 26TH DECEMBER, 2018
DATE AFTER 45 DAYS: 9TH FEBRUARY, 2019
Example 3
INPUT: DAY NUMBER: 500
YEAR: 2018

P a g e | 106
DATE AFTER (NDAYS): 33
OUTPUT: DAY NUMBER OUT OF RANGE.

CODING

P a g e | 107
P a g e | 108
P a g e | 109
COMPILING

OUTPUTS

P a g e | 110
ALGORITHM
Step 1: Start
Step 2: Declare and ini alize variable like ‘dayNumber’ , ‘year’.
Step 3: Validate Inputs and Display Result
- Check if the entered day number is between 1 and 366, the year is in the range of 1000 to
9999, and "N" is between 1 and 100.

- If the inputs are valid:


- Calculate the ini al date using the day number and year.
- Display the ini al date.
- Calculate the future date a er "N" days.
- Display the future date.

- If the inputs are not valid, display an error message.

Step 4: Calculate Ini al Date


- Ini alize an array `daysInMonth` with the number of days in each month.

- Ini alize variables for the month and day.

- Iterate to find the corresponding month and day based on the day number.

- Display the ini al date.

P a g e | 111
Step 5: Calculate Future Date
- Ini alize the variable `futureDayNumber` by adding "N" days to the input day number.

- While `futureDayNumber` is greater than 365:


- Subtract 365 from `futureDayNumber`.
- Increment the year.

- Calculate and display the future date.

Step 6: Stop

VARIABLE DESCRIPTION
Variable name Data type Purpose
dayNumber int To represent the day of the year

year int To represent the year (4 digits).

nDays int To calculate the future date.

P a g e | 112
PROGRAM 19
Write a program to declare a single dimensional array a[] and a square matrix b[][] of size N,
where N>2 and N<10. Allow the user to input posi ve into the single dimensional array.

Perform the following task on the matrix:


(a) Sort the element of the single dimensional array in ascending order using any standard
sor ng technique and display the sorted element.
(b) Fill the square matrix b[][] in the following format.
If the array a[] = {5,2,8,1} then a er sor ng a[] ={1,2,5,8}
Then, the matrix b[][] would fill as below:
1 2 5 8
1 2 5 8
1 2 5 8

1 2 5 8
(c) Display the filled matrix in the above format
Test your program for the following data and some random data.
Example 1.
INPUT: N=3
ENTER ELEMENTS OF SINGLE DIMENSIONAL ARRAY: 3 1 7
OUPUT: SORTED ARRAY: 1 3 7
FILLED MATRIX
1 3 7
1 3 7
1 3 7

P a g e | 113
Example 2.
INPUT: N=13
OUTPUT: MATRIX SIZE OUT OF RANGE.

CODING

P a g e | 114
COMPILING

P a g e | 115
OUTPUT

ALGORITHM
Step 1: Start
Step 2: Declare and ini alize variable like ‘N’, ‘a[]’.
Step 3: If N is less than or equal to 2 OR N is greater than or equal to 10, then display "MATRIX
SIZE OUT OF RANGE" and go to Step 11.
Step 4: Declare an integer array a[] of size N.
Step 5: Read N elements into array a[] from the user.
Step 6: Sort array a[] in ascStoping order.
Step 7: Display "Sorted array: " followed by the elements of array a[].
Step 8: Declare a square matrix b[][] of size N x N.
Step 9: Fill the matrix b[][] using the sorted elements of array a[].
- For each row i from 0 to N-1:
- For each column j from 0 to N-1:
P a g e | 116
- Assign b[i][j] = a[j].
Step 10: Display "Filled matrix:" followed by the elements of matrix b[][].
Step 11: Stop

VARIABLE DESCRIPTION
Variable name Data type Purpose
N int Size of the array and matrix
a[] int[] Single dimensional array to store user input.
b[][] int[][] Square matrix to store the sorted array elements.
i int Loop variable for rows in matrix filling
j int Loop variable for columns in matrix filling

P a g e | 117
PROGRAM 20
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 UPPER CASE.
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
concatena ng the word by its reverse(excluding the last character).
(c) Display the original sentence along with the converted sentence.

Test your program for the following data and some random data:

Example 1

INPUT: THE BIRD IS FLYING.


OUTPUT: THE BIRD IS FLYING.
THEHT BIRDRIB ISI FLYING.NIYLF
Example 2

INPUT: YOU MUST BE CRAZY#


OUTPUT: INVALID INPUT.

P a g e | 118
CODING

P a g e | 119
COMPILING

P a g e | 120
OUTPUTS

ALGORITHM
Step 1: Start
Step 2: Declare and ini alize variable like ‘isValid’, ‘words’.
Step 3: Read a sentence terminated by '.', '?', or '!' from the user.
Step 4: Check the validity of the sentence.
- If the sentence does not match the pa ern "[A-Z ]+[.?!]", display "INVALID INPUT" .
Step 5: Split the sentence into words.
Step 6: Ini alize an empty StringBuilder for the result.
Step 7: For each word in the sentence:
- a. Check if the last character is '.', '?', or '!'.
- b. Remove the punctua on if present and store it.
- c. Check if the word is a palindrome.

P a g e | 121
- d. If it is not a palindrome, appStop the original word, its reverse (excluding the last
character), and the stored punctua on to the result.
- e. If it is a palindrome, appStop the original word and the stored punctua on to the result.
Step 8: Display the original sentence and the converted sentence.
Step 9: Stop

VARIABLE DESCRIPTION
Variable name Data type Purpose

sentence String Input variable to store the user- provided sentence.


isValid boolean Flag to check the validity of the input sentence.
words String[] Array to store words extracted from the input sentence.
result StringBuilder StringBuilder to store the converted sentence
word String Temporary variable to store each word during processing
punctua on String Temporary variable to store the punctua on at the Stop of
words.
lastChar char Temporary variable to store the last character of word.
i int Loop variable for itera ng through words.

P a g e | 122
I, SAYED AL AMAAN ZAIDI of class XII
have done this project with the help of the
websites.

1. YOUTUBE.COM
2. SHAALA.COM
THE BOOK WHICH ARE USED BY ME
1. Computer Science with Java.

P a g e | 123
Here I have come to an end of the computer project. I
tried my best to include all the points which were
necessary and are required for the project. this project
was very interes ng and I learned many things from it.

P a g e | 124
int – integer
char – character
u l – u lity
args – arguments

P a g e | 125

You might also like