0% found this document useful (0 votes)
46 views88 pages

Java COMPUTER PROJECT Cms

Here is the program to perform the given tasks on a square matrix: import java.util.Scanner; import java.util.Arrays; public class MatrixOperations { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter order of square matrix (between 4-9): "); int M = sc.nextInt(); int A[][] = new int[M][M]; System.out.println("Enter elements of matrix:"); for(int i=0; i<M; i++) { for(int j=0; j<M; j++) { A[i][
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
46 views88 pages

Java COMPUTER PROJECT Cms

Here is the program to perform the given tasks on a square matrix: import java.util.Scanner; import java.util.Arrays; public class MatrixOperations { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter order of square matrix (between 4-9): "); int M = sc.nextInt(); int A[][] = new int[M][M]; System.out.println("Enter elements of matrix:"); for(int i=0; i<M; i++) { for(int j=0; j<M; j++) { A[i][
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 88

COMPUTER PROJECT

NAME: ANANT SHUKLA


CLASS: XII
SECTION: B
SCHOOL: CITY MONTESSORI SCHOOL,
ALIGANJ-1
ROLL NO: 10
INDEX NO:
UID:

INTERNAL EXAMINER SIGNATURE


______________

EXTERNAL EXAMINER SIGNATURE


______________

1
Acknowledgement
I would like to express my special thanks of
gratitude to my teacher Mr. Sarfraz Ahmad Sir
who gave me the golden opportunity to do
this wonderful project which also helped me in
doing a lot of Research and I came to know
about so many new things I am really thankful
to him. I am also thankful to my principals Mrs.
Jyoti Kashyap ma’am and Mrs. Shivani Singh
ma’am for always encouraging us to give our
best in everything. Their motivation helped a
lot to complete this project on time.
I would also like to thank my parents and
friends who helped me in finalizing this project
within the limited time frame.

Anant Shukla

2
Index
S.No. Program Page No.
1 Circular Prime Number 4-7
2 Boundary and Diagonals of a Square Matrix 8-11
3 Vowel words and shift of words 12-14
4 Find number whose sum of all its digits is equal to N 15-17
5 Rotate the matrix 90ᵒ clockwise and corner element sum 18-21
6 Find the number of vowels and consnants in each word 22-25
7 Number which is composite as well as a magic number. 26-28
8 Check if the given matrix is symmetric or not. 29-32
9 Deleting given word from the string 33-35
10 An ISBN ( International Standard Book Number) 36-38
11 Create a mirror image of the inputted matrix. 39-41
12 Display and the count of palindromic words in the sentence 42-44
13 A prime palindrome which is prime as well as a palindrome. 45-47
14 Arrange the sentence in alphabetical order of the words. 48-50
15 Find the maximum and minimum value in the matrix 51-55
16 Display a Natural number less than 1000 in words 56-58
17 Encryption of a string to maintain their secrecy 59-62
18 Check whether the date entered is valid or not. 63-64
19 Denomination of an input amount 65-67
20 Kaprekar numbers 68-69
21 Display the words in ascending order of their frequency. 70-73
22 Program on Inheritance 74-77
23 Prime using recursive technique 78-80
24 Program on Data Structure - STACK 81-84
25 Program on Data Structure – Simple Queue 85-88

3
Question 1
A Circular Prime is a prime number that remains prime under cyclic shifts of its digits. When the
leftmost digit is removed and replaced at the end of the remaining string of digits, the generated number
is still prime. The process is repeated until 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.

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

Example 1
INPUT :N = 197

OUTPUT:
197
971
719
197 IS A CIRCULAR PRIME

Example 2
INPUT :N = 1193

OUTPUT:
1193
1931
9311
3119

1193 IS A CIRCULAR PRIME

Example 3
INPUT :N = 29

OUTPUT:
29
92
29 IS NOT A CIRCULAR PRIME

4
ALGORITHM

Step 1: Initialize a scanner to read the input number.


Step 2: Prompt the user to enter a number.
Step 3: Read the input number and store it in a variable 'n'.
Step 4: Initialize a flag with the value 1. This flag will help us determine if the number is
a circular prime.
Step 5: Check if the entered number 'n' is a prime number. If it is prime, proceed to the
next steps. Otherwise, skip to the end and print that it's not a circular prime.
Step 6: If 'n' is prime, print 'n' and proceed with the following steps.
Step 7: Calculate the number of digits in 'n' and store it in a variable 'dc'.
Step 8: Calculate a divisor 'div' as 10 raised to the power of (dc - 1).
Step 9: Initialize a variable 'n2' with the value of 'n'.
Step 10: Start a loop from 1 to 'dc - 1'.
Step 11: Inside the loop, split 'n2' into two parts, 't1' and 't2', and rotate the digits of 'n2'.
Step 12: Check if the rotated number 'n2' is prime. If it's prime, continue with the next
rotation. If it's not prime, set the flag to 0 and break out of the loop.
Step 13: After the loop, check the flag. If the flag is still 1, it means all rotations are
prime, and 'n' is a circular prime.
Step 14: If the flag is 1, print 'n' is a Circular Prime. If the flag is 0, print 'n' is NOT a
Circular Prime.

PROGRAM

import java.util.*;
class CircularPrime {
public static boolean isPrime(int num) {
int c = 0;
for (int i = 1; i <= num; i++) {
if (num % i == 0) //checking for prime
{ c++;
}
}
if (c == 2)
return true; //number is prime
else
return false; //number is not prime
}
public static int getDigitCount(int num) {
int c = 0;
while (num != 0) {
c++; to count number of digits
num /= 10;
}
5
return c;
}
public static void main() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number to check ");
int n = sc.nextInt();
int flag = 1;
if (isPrime(n)) { //if original number is prime
System.out.println(n);
int dc = getDigitCount(n);
int div = (int)(Math.pow(10, dc - 1));
int n2 = n;
for (int i = 1; i < dc; i++) {
int t1 = n2 / div;
int t2 = n2 % div;
n2 = t2 * 10 + t1; //calculating the shifted number
System.out.println(n2); //check if cyclic number is primeor not
if (!isPrime(n2)) {
flag--;
break;
}
}
}
if (flag == 1) //number is circular prime
{ System.out.println(n + " is a Circular Prime");
} else { //number is not circular prime
System.out.println(n + " is NOT a Circular Prime");
}
}
}

VARIABLE DESCRIPTION TABLE

Variable Data Type Description


num int The number to be checked
c int Counter variable
i int Looping variable
flag int Flag variable to indicate if the number is a circular prime
n int The number entered by the user
dc int The number of digits in the number
div int Divisor used to calculate the shifted number
n2 int The shifted number
t1 int Temporary variable
t2 int Temporary variable

6
OUTPUT
Enter number to check 234
234
342
423
234 is NOT a Circular Prime
Enter number to check 1193
1193
1931
9311
3119
1193 is a Circular Prime

7
Question 2
Write a program to declare a square matrix A[][] of order (M x 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:
1. Sort the non-boundary elements in ascending order using any standard sorting technique and
rearrange them in the matrix.
2. Calculate the sum of both the diagonals.
3. Display the original matrix, rearranged matrix and only the diagonal elements of the rearranged
matrix.
Test your program with the sample 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
REARRANGED MATRIX
9 2 1 5
8 3 6 4
15 8 13 11
7 12 23 8
DIAGONAL ELEMENTS
9 5
3 6
8 13
7 8

ALGORITHM

Step 1: Start
Step 2: Declare a constant variable 'M' representing the order of the square matrix,
ensuring it is greater than 3 and less than 10.
Step 3: Declare a 2D array A[][] of order (M x M).
Step 4: Allow the user to input positive integers into the matrix A[][].
Step 5: Declare a 1D array 'nonBoundaryElements' to store non-boundary elements of the
matrix.
Step 6: Traverse the matrix excluding the boundary elements, and populate the
'nonBoundaryElements' array.
Step 7: Use any standard sorting technique to sort the 'nonBoundaryElements' array in
ascending order.
Step 8: Traverse the matrix excluding the boundary elements again, and replace the
elements with the sorted elements from 'nonBoundaryElements'.

8
Step 9: Declare variables 'sumDiagonal1' and 'sumDiagonal2' to store the sum of both
diagonals.
Step 10: Traverse the matrix diagonally, summing the elements for both diagonals.
Step 11: Display the original matrix.
Step 12: Display the rearranged matrix.
Step 13: Display only the diagonal elements of the rearranged matrix.
Step 14: End.

Note: Ensure to handle user input validation, such as checking if the entered order 'M' is
within the specified range and that the user inputs positive integers.

PROGRAM
import java.util.*;
class mtrxsort {
int m;
int a[][];
public void inputarr() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter size of matrix ");
m = sc.nextInt();
if (m <= 3 || m >= 10) {
System.out.println("ERROR (Matrix size out of range)");
System.exit(0); //exiting the matrix as size is out of range
}
a = new int[m][m];
System.out.println("Enter matrix elements (Only positive integers)");
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = sc.nextInt(); //inputting matrix elements
}
}
}
public static void sortnb(int a[][], int m) {
int b[] = new int[(m - 2) * (m - 2)]; //array initialization
int k = 0;
for (int i = 1; i < m - 1; i++) {
for (int j = 1; j < m - 1; j++) {
b[k++] = a[i][j];
}
}
//binary sorting
for (int i = 0; i < k - 1; i++) {
for (int j = 0; j < k - i - 1; j++) {
if (b[j] >b[j + 1]) {
int t = b[j];
9
b[j] = b[j + 1];
b[j + 1] = t;
}
} }

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

public static void diagonalsum(int a[][], int m) {


int sum = 0;
System.out.println("Diagonal Elements");
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
if (i == j || i + j == m - 1) {
sum = sum + a[i][j]; //calculating sum of diagonals
System.out.print(a[i][j] + "\t");
} else {
System.out.print("\t");
}
}
System.out.println();
}
System.out.println("Sum of Diagonal elements " + sum); //printing diagonal sum
}

public static void display(int a[][], int m) {


for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
System.out.print(a[i][j] + "\t");
}
System.out.println();
}
}
public static void main() {
mtrxsort obj = new mtrxsort();
obj.inputarr();
System.out.println("ORIGINAL MATRIX");
obj.display(obj.a, obj.m); //displaying original matrix

sortnb(obj.a, obj.m); //sorting the matrix


System.out.println("REARRANGED MATRIX");

10
display(obj.a, obj.m); //displaying sorted matrix

diagonalsum(obj.a, obj.m);
}}
VARIABLE DESCRIPTION TABLE

Variable Data Type Description


m int Size of the matrix
a int[][] Array to store the matrix elements
b int[] Temporary array used for sorting
k int Counter variable
i int Looping variable
j int Looping variable
sum int Variable to store the sum of diagonal elements
t int Temporary variable

OUTPUT
Enter size of matrix 3
ERROR (Matrix size out of range)
Enter size of matrix 4
Enter matrix elements (Only positive integers)
12
46346
45
54
435
457
253
574
235
8
243
67
24
68
23
4697
ORIGINAL MATRIX
12 46346 45 54
435 457 253 574
235 8 243 67
24 68 23 4697
REARRANGED MATRIX
12 46346 45 54
435 8 243 574
235 253 457 67
24 68 23 4697
Diagonal Elements
12 54
8 243
253 457
24 4697
Sum of Diagonal elements: 574
11
Question 3
Write a program to accept a sentence which may be terminated by either '.', '?' or '!' only. The
words may be separated by more than one blank space and are in UPPER CASE.
Perform the following tasks:
1. Find the number of words beginning and ending with a vowel.
2. Place the words which begin and end 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 ENDING WITH A VOWEL = 3
ANAMIKA ARE ANYMORE AND SUSAN NEVER GOING TO QUARREL

Example 2
INPUT: HOW ARE YOU@
OUTPUT: INVALID INPUT

ALGORITHM

Step 1: Start
Step 2: Accept a sentence terminated by '.', '?' or '!' and store it in a string variable.
Step 3: Tokenize the sentence into words, considering multiple blank spaces as
separators.
Step 4: Initialize two lists, one for words beginning and ending with a vowel (let's call it
'vowelWords'), and another for the remaining words (let's call it 'remainingWords').
Step 5: Traverse each word in the tokenized sentence.
Step 6: Check if the current word begins and ends with a vowel.
Step 7: If yes, add it to the 'vowelWords' list; otherwise, add it to the 'remainingWords'
list.
Step 8: Concatenate the 'vowelWords' list with the 'remainingWords' list to create the
final list of words.
Step 9: Display or return the modified sentence with words beginning and ending with
vowels placed at the beginning.
Step 10: End.

PROGRAM

import java.util.*;
public class VowelWord { //to check for vowel

public static boolean isVowel(char ch)


{
ch = Character.toUpperCase(ch);
12
boolean vow = false;
if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
vow = true; //if vowel
return vow; //return if a vowel
}

public static void main()


{
Scanner sc = new Scanner(System.in);
System.out.println("Enter sentence");
String str = sc.nextLine();
str = str.trim();
str = str.toUpperCase();
int len = str.length();
char lastChar = str.charAt(len - 1); //chopping last character
if (lastChar != '.' && lastChar != '?' && lastChar != '!') {
System.out.println("INVALID INPUT"); //if character is not as allowed
return;
}
str = str.substring(0, len - 1);
StringTokenizer st = new StringTokenizer(str);
int c = 0;
String ns = "";
String nl = "";
while (st.hasMoreTokens()) {
String word = st.nextToken();
int wordLen = word.length();
if (isVowel(word.charAt(0)) && isVowel(word.charAt(wordLen - 1))) {
c++;
ns = ns + word + " "; //words starting and ending with a vowel
} else {
nl = nl + word + " "; //words not starting or ending with a vowel
}
}
String newStr = ns + " " + nl;
System.out.println("NUMBER OF WORDS BEGINNING AND ENDING WITH A
VOWEL = " + c);
System.out.println(newStr);
}
}

13
VARIABLE DESCRIPTION TABLE

Variable Data Type Description


ch char Character to check if it is a vowel
vow boolean Boolean flag to indicate if the given character is a vowel
str String Sentence entered by the user
len int Length of the sentence
lastChar char Last character of the sentence
st StringTokenizer StringTokenizer object to tokenize the sentence
Counter variable to count the number of words starting and
c int ending with a vowel
ns String String to store the words starting and ending with a vowel
nl String String to store the words not starting or ending with a vowel
word String Word tokenized from the sentence
wordLen int Length of the word
String to store the rearranged sentence with the words
starting and ending with a vowel followed by the words not
newStr String starting or ending with a vowel

OUTPUT

Enter sentence
INDIA IS A DEVELOPING NATION
INVALID INPUT
Enter sentence
INDIA IS A DEVELOPING NATION.
NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL = 2
INDIA A IS DEVELOPING NATION
Enter sentence
ANAMIKA AND SUSAN ARE NEVER GOING TO QUARREL ANYMORE.
NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL = 3
ANAMIKA ARE ANYMORE AND SUSAN NEVER GOING TO QUARREL

14
Question 4
Given two positive 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 up
to 11 is 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
N = 11
OUTPUT :
INVALID INPUT
Example 4
INPUT :
M = 112
N = 130
OUTPUT :
INVALID INPUT

ALGORITHM
Step 1: Start
Step 2: Accept positive numbers M and N from the user.
Step 3: Check if M is between 100 and 10000 and if N is less than 100. If not, display an
error message and end the program.
Step 4: Initialize a variable 'currentNumber' with M.
Step 5: Iterate until a suitable number is found.
STEP 6: Calculate the sum of digits of 'currentNumber'.
STEP 7: If the sum is equal to N, display 'currentNumber' and the total number of digits,
then end the program.
STEP 8: If not, increment 'currentNumber' by 1 and repeat from Step 6.
15
Step 9: End.
PROGRAM

import java.util.Scanner;
class number_mn {

public static void main() {


Scanner in = new Scanner(System.in);
System.out.print("Enter M: ");
int m = in.nextInt();
System.out.print("Enter N: ");
int n = in.nextInt();
if (m < 100 || m > 10000 || n < 1 || n >= 100) {
System.out.println("Invalid Input"); //word not under limit
System.exit(0);
}

int num = -1, count = 0;


for (int i = m + 1;; i++) {
int sum = 0;
count = 0; //reset count to zero
int t = i; //temporary variable to find sum
while (t != 0) {
int d = t % 10;
sum += d; //to find sum of digits of the number
t /= 10;
count++; //number of digit
}

if (sum == n) { //sum of digits of number equal to n


num = i;
break;
}
}

if (num == -1) { //no number found whose digit sum is equal to n


System.out.println("Number not found");
} else {
System.out.println("The number = " + num);
System.out.println("Total number of digits = " + count); //number of digits
}

}
}

16
VARIABLE DESCRIPTION TABLE

Variable Data Type Description


m int Lower limit of the range
n int Sum of digits of the number
num int Number whose sum of digits is equal to n
count int Counter variable to count the number of digits
i int Looping variable
sum int Sum of digits of the temporary variable t
t int Temporary variable to find sum
d int Digit of the number

OUTPUT

Enter M: 120
Enter N: 23
The number = 599
Total number of digits = 3
Enter M: 1500
Enter N: 25
The number = 1699
Total number of digits = 4
Enter M: 99
Enter N: 11
Invalid Input

17
Question 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 rows and the number of columns, such that M must be greater than 2
and less than 10. Accept the value M as user input. Display an appropriate message for an
invalid input. Allow the user to input integers into the matrix. Perform the following tasks:
1. Display the original matrix.
2. Rotate the matrix 90ᵒ clockwise as shown below:
Original matrix Rotated matrix
1 2 3 7 4 1
4 5 6 8 5 2
7 8 9 9 6 3

3. Find the sum of the elements of the four corners of the matrix.
Example 1
INPUT :
M=3

OUTPUT :
ORIGINAL MATRIX

MATRIX AFTER ROTATION

Sum of the corner elements = 20


Example 2
INPUT :
M=4

OUTPUT :
ORIGINAL MATRIX MATRIX AFTER ROTATION

Sum of the corner elements = 18

18
ALGORITHM

Step 1: Start
Step 2: Accept the number of rows and columns 'M' from the user.
Step 3: Check if 'M' is greater than 2 and less than 10. If not, display an error message
and end the program.
Step 4: Declare a square matrix A[][] of order M×M.
Step 5: Allow the user to input integers into the matrix A[][].
Step 6: Display the original matrix A[][].
Step 7: Initialize a new matrix 'rotatedMatrix' of order M×M.
Step 8: Perform the 90ᵒ clockwise rotation of the matrix A[][] and store the result in
'rotatedMatrix'.
Step 9: Display the rotated matrix 'rotatedMatrix'.
Step 10: Calculate the sum of the elements at the four corners of the original matrix
A[][].
Step 11: Display the sum of the corner elements.
Step 12: End.

PROGRAM

import java.util.*;
class rotatematrix {
public static void main() {
Scanner sc = new Scanner(System.in);

System.out.println("Enter the number of rows and columns(> 2 and < 10) : ");
int m = sc.nextInt();

if (m <= 2 || m >= 10) { //the value inputted is out of range


System.out.println("Out of Range");
System.exit(0);
}

int a[][] = new int[m][m]; //initializing matrix


int b[] = new int[m * m]; //initializing array
int i, j, ctr, c;

System.out.println("Enter numbers for the matrix: ");


for (i = 0; i < m; i++) {
for (j = 0; j < m; j++) {
a[i][j] = sc.nextInt(); //inputting elements
}
}

19
ctr = 0;

System.out.println("ORIGINAL MATRIX"); //printing original matrix

for (i = 0; i < m; i++) {


for (j = 0; j < m; j++) {
System.out.print(a[i][j] + " ");
b[ctr++] = a[i][j]; //taking matrix into an array
}
System.out.println();
}

c = m - 1;
ctr = 0;

while (c >= 0) {

for (i = 0; i < m; i++)


a[i][c] = b[ctr++]; //rearranging matrix

c--;
}

System.out.println("MATRIX AFTER ROTATION");

for (i = 0; i < m; i++) {


for (j = 0; j < m; j++) {
System.out.print(a[i][j] + " "); //printing rearranging matrix
}
System.out.println();
}

System.out.println("Sum of the corner elements = " + (a[0][0] + a[0][m - 1] + a[m -


1][0] + a[m - 1][m - 1]));
}
}

VARIABLE DESCRIPTION TABLE

Variable Data Type Description


m int The number of rows and columns of the matrix
a int[][] The matrix
b int[] Array to store the matrix elements in linear order
i int Looping variable for the rows of the matrix
j int Looping variable for the columns of the matrix
ctr int Counter variable to keep track of the index in the array b
Counter variable to keep track of the column index of the matrix
c int a while rearranging

20
OUTPUT
Enter the number of rows and columns(> 2 and < 10) :
3
Enter numbers for the matrix:
234
1
2342
12
3
12
325
2354
769
ORIGINAL MATRIX
234 1 2342
12 3 12
325 2354 769
MATRIX AFTER ROTATION
325 12 234
2354 3 1
769 12 2342
Sum of the corner elements = 3670

21
Question 6
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:
1. Convert the first letter of each word to uppercase.
2. 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:
Intelligence Plus Character Is Education
WORD VOWELS CONSONANTS
Intelligence 5 7
Plus 1 3
Character 3 6
Is 1 1
Education 5 4
Example 2
INPUT: God is great.
OUTPUT:
God Is Great
WORDS VOWELS CONSONANTS
God 1 2
Is 1 1
Great 2 3
Example 3
INPUT: All the best!
OUTPUT:
Invalid Input.

ALGORITHM

Step 1: Start
Step 2: Accept a sentence terminated by '.' or '?' from the user.
Step 3: Check if the sentence terminates with '.' or '?'. If not, display an error message and
end the program.
Step 4: Tokenize the sentence into words using a single blank space as a separator.
Step 5: Iterate through each word in the tokenized sentence.
Step 6: Convert the first letter of each word to uppercase.
Step 7: Initialize variables for counting vowels and consonants in each word.
Step 8: For each word, iterate through its characters.
Step 9: Check if the current character is a vowel. If yes, increment the vowel count;
otherwise, increment the consonant count.
22
Step 10: Display the word with its first letter converted to uppercase.
Step 11: Display the count of vowels and consonants for the current word.
Step 12: Repeat from Step 5 for the next word.
Step 13: End.

PROGRAM

import java.util.*;
class wordsincap {
public static void main() {
int i, j, vowels, cons, p, l;
String str, word, t;
char ch, ch1;

Scanner sc = new Scanner(System.in);


System.out.println("Enter : ");
str = sc.nextLine();
l = str.length();
ch = str.charAt(l - 1);
if (ch != '.' && ch != '?') {
System.out.println("INVALID INPUT"); //does not end with .or ?
System.exit(0);
}
p = 0;
vowels = 0;
cons = 0;

t = str + " ";


str = "";

for (i = 0; i <t.length(); i++) {


ch = t.charAt(i);
if (ch == ' ') {
word = t.substring(p, i);
ch1 = word.charAt(0);
word = Character.toUpperCase(ch1) + word.substring(1); //first letter uppercase
str += word + " "; //adding to string
p = i + 1;

}
}

System.out.println("\n" + str); //printing the string

System.out.print("\nWord");
for (j = 15 - 4; j >= 1; j--)
23
System.out.print(" ");

System.out.println("\tVowels\tConsonants");

p = 0;
for (i = 0; i < l; i++) {
ch = str.charAt(i);
if (ch != ' ' && ch != '.' && ch != '?') {
if ((ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122)) {

if ("aeiouAEIOU".indexOf(ch) != -1) //if vowel


vowels++; //counting vowels in word
else
cons++; //counting consonants in word
}
} else {
word = str.substring(p, i);
System.out.print(word);
for (j = 15 - word.length(); j >= 1; j--)
System.out.print(" "); //printing number of vowels and consonants
System.out.println("\t " + vowels + "\t " + cons);
p = i + 1;
vowels = cons = 0;
}
}
}
}

VARIABLE DESCRIPTION TABLE

Variable Data Type Description


i int Loop counter for iterating over the string str.
j int Loop counter for iterating over the string t.
vowels int Counter for the number of vowels in a word.
cons int Counter for the number of consonants in a word.
p int Pointer to the current index in the string str.
l int Length of the string str.
str String The input string.
word String The current word being processed.
A temporary string used to store the input string with a space
t String appended to the end.
ch char The current character in the string str or t.
ch1 char The first character of the current word.

24
OUTPUT

Enter :
IS WAR BAD?

IS WAR BAD?

Word Vowels Consonants


IS 1 1
WAR 1 2
BAD 1 2

25
Question 7
A composite Magic number is a positive integer which is composite as well as a magic
number.
Composite number: A composite number is a number which has more than two factors. For
example: 10 Factors are: 1,2,5,10
Magic number: A Magic number is a number in which the eventual sum of the digit d is
equal to 1. For example: 28 = 2+8=10= 1+0=1
Accept two positive integers m and n, where m is less than n as user input. Display the
number of composite magic integers that are in the range between m and n (both inclusive)
and output them along with frequency, in the format specified below:
Example 1:
INPUT:
m = 10
n = 100
OUTPUT:
THE COMPOSITE MAGIC INTEGERS ARE:
10, 28, 46, 55, 64, 82, 91, 100
FREQUENCY OF COMPOSITE MAGIC INTEGERS IS: 8
Example 2:
INPUT:
m = 1200
n = 1300
OUTPUT:
THE COMPOSITE MAGIC INTEGERS ARE:
1207, 1216, 1225, 1234, 1243, 1252, 1261, 1270, 1288
FREQUENCY OF COMPOSITE MAGIC INTEGERS IS: 9
Example 3:
INPUT:
m = 120
n = 99
OUTPUT:
INVALID INPUT

ALGORITHM

Step 1: Start
Step 2: Accept two positive integers m and n as user input.
Step 3: Check if m is less than n. If not, display an error message and end the program.
Step 4: Initialize a list 'compositeMagicIntegers' to store numbers that are both composite
and magic in the range [m, n].
Step 5: Iterate through each number in the range [m, n].
Step 6: Check if the current number is composite and magic using separate functions for
checking compositeness and magic property.
Step 7: If yes, add the number to the 'compositeMagicIntegers' list.
Step 8: Display the 'compositeMagicIntegers' list.
Step 9: Display the frequency of composite magic integers.
Step 10: End.

26
PROGRAM

import java.util.*;
class compositeMagicNumber
{
public static void main() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter m: ");
int m = sc.nextInt();

System.out.print("Enter n: "); //input number


int n = sc.nextInt();

if (m < 1 || n < 1 || m > n) {


System.out.println("Invalid input");
System.exit(0);
}

System.out.println("The composite magic numbers are:");


int count = 0;
for (int i = m; i <= n; i++) {

boolean isComposite = false;


for (int j = 2; j < i; j++) {
if (i % j == 0) { //finding if composite
isComposite = true;
break;
}
}

if (isComposite &&i != 1) { //finding if a magic number


int num = i;
while (num > 9) {
int sum = 0;
while (num != 0) {
int d = num % 10;
num /= 10;
sum += d; //sum of digits
}
num = sum;
}

if (num == 1) {
count++; //counting frequency of the numbers
System.out.print(i + " ");
27
}
}
}
System.out.println(); //printing the frequency
System.out.println("Frequency of composite magic numbers: " + count);
}
}

VARIABLE DESCRIPTION TABLE

Variable Data Type Description


m int The lower bound of the range of numbers to be checked.
n int The upper bound of the range of numbers to be checked.
count int A counter for the number of composite magic numbers found.
A loop counter for iterating over the range of numbers from m to
i int n.
j int A loop counter for iterating over the divisors of i.
isComposite boolean A flag indicating whether i is a composite number.
num int A variable used to store the sum of the digits of i.
d int A variable used to store the digit at the current position in i.

OUTPUT

Enter m: 130
Enter n: 250
The composite magic numbers are:
136 145 154 172 190 208 217 226 235 244
Frequency of composite magic numbers: 10

28
Question 8
Write a program to declare a square matrix A[][] of order MXM where M is an positive
integer and represents row and column. M should be greater than 2 and less than 10.Accept
the value of M from the user. Display an appropriate message for invalid input.
Perform the following task:
1. Display the original matrix
2. Check if the given matrix is symmetric or not. If the element of the ith row and jth
column is the same as the element of the jth row and ith column.
3. Find the sum of the left and right diagonal of the matrix and display them
Example 1
INPUT : M=3
1 2 3
2 4 5
3 5 6
OUTPUT :
ORIGINAL MATRIX
1 2 3
2 4 5
3 5 6
THE GIVEN MATRIX IS SYMMETRIC
The sum of the left diagonal = 11
The sum of the right diagonal = 10
Example 2
INPUT : M=4
7 8 9 2
4 5 6 3
8 5 3 1
7 6 4 2
OUTPUT :
ORIGINAL MATRIX

7 8 9 2
4 5 6 3
8 5 3 1
7 6 4 2
THE GIVEN MATRIX IS NOT SYMMETRIC
The sum of the left diagonal = 17
The sum of the right diagonal = 20
Example 3
INPUT : M = 22
OUTPUT : THE MATRIX SIZE IS OUT OF RANGE

ALGORITHM

Step 1: Start
Step 2: Accept a positive integer 'M' from the user.
Step 3: Check if 'M' is greater than 2 and less than 10. If not, display an error message
and end the program.
Step 4: Declare a square matrix A[][] of order MXM.
29
Step 5: Allow the user to input integers into the matrix A[][].
Step 6: Display the original matrix A[][].
Step 7: Initialize a variable 'isSymmetric' to true.
Step 8: Check if the matrix A[][] is symmetric:
Step 9: Iterate through each element of the matrix.
Step 10: Compare the element of the ith row and jth column with the element of the jth
row and ith column.
Step 11: If any pair of elements is not equal, set 'isSymmetric' to false and break from the
loop.
Step 12: If 'isSymmetric' is true, display a message indicating that the matrix is
symmetric; otherwise, display a message indicating that it is not.
Step 13: Calculate the sum of the left diagonal of the matrix.
Step 14: Calculate the sum of the right diagonal of the matrix.
Step 15: Display the sum of the left diagonal.
Step 16: Display the sum of the right diagonal.
Step 17: End.

PROGRAM

import java.util.*;
class symMatrix
{
public static void display(int A[][])
{
for (int r = 0; r <A.length; r++) {
for (int c = 0; c <A.length; c++) {
System.out.print(A[r][c] + "\t"); //displaying matrix elements
}
System.out.println();
}
}

public static boolean isSymmetric(int A[][])


{
for (int r = 0; r <A.length; r++) {
for (int c = 0; c < r; c++) {
if (A[r][c] != A[c][r]) { //checking if mirror position elements are same or not
return false;
}
}
}
return true;
}

public static void diagsum(int A[][])


30
{
int ldiag = 0, rdiag = 0;
for (int i = 0; i <A.length; i++) {
ldiag += A[i][i]; //adding left diagonal elements
rdiag += A[i][A.length - i - 1]; //adding right diagonal elements
}
System.out.println("The sum of the left diagonal = " + ldiag);
System.out.println("The sum of the right diagonal = " + rdiag);
}

public static void main()


{
int M;
Scanner sc = new Scanner(System.in);
System.out.print("M = ");
M = sc.nextInt();
if (M <= 2 || M >= 10) {
System.out.println("THE MATRIX SIZE IS OUT OF RANGE");
} else {
int A[][] = new int[M][M];
System.out.println("Enter matrix elements");
for (int r = 0; r < M; r++) {
for (int c = 0; c < M; c++) {
A[r][c] = sc.nextInt(); //inputting matrix
}
}
System.out.println("ORIGINAL MATRIX");
display(A);
if (isSymmetric(A)) //if isSymmetric(A) returns true
System.out.println("THE GIVEN MATRIX IS SYMMETRIC");
else //if isSymmetric(A) returns false
System.out.println("THE GIVEN MATRIX IS NOT SYMMETRIC");
diagsum(A);
}
}
}

VARIABLE DESCRIPTION TABLE

Variable Data Type Description


M int The size of the square matrix.
A int[][] A 2D array representing the square matrix.
ldiag int The sum of the elements on the left diagonal of the matrix.
rdiag int The sum of the elements on the right diagonal of the matrix.
i int Loop control variable.
r,c int Loop control variable.

31
OUTPUT

M=4
Enter matrix elements
124
12
35
12
789
45
908
54
087

67
98
456
089

576
0897
679
ORIGINAL MATRIX
124 12 35 12
789 45 908 54
87 67 98 456
89 576 897 679
THE GIVEN MATRIX IS NOT SYMMETRIC
The sum of the left diagonal = 946
The sum of the right diagonal = 1076

32
Question 9
Write a program to accept a sentence which may be terminated by either '.', '?', or '!' only.
Any other character may be ignored. The words may be separated by more than one blank
space and are in UPPER CASE.
Perform the following tasks.
1. Accept the sentence and reduce all the extra blank space between two words to a single blank
space.
2. Accept a word from the user which is part of the sentence along with its position number and
delete the word and display the sentence.
Test your program with the sample data and some random data.
Example 1
INPUT: A MORNING WALK IS A IS BLESSING FOR THE WHOLE DAY.
WORD TO BE DELETED: IS
WORD POSITION IN THE SENTENCE: 6
OUTPUT: A MORNING WALK IS A BLESSING FOR THE WHOLE DAY.
Example 2
INPUT: AS YOU SOW, SO SO YOU REAP.
WORD TO BE DELETED: SO
WORD POSITION IN THE SENTENCE: 4
OUTPUT: AS YOU SOW, SO YOU REAP.
Example 3
INPUT: STUDY WELL ##
OUTPUT: INVALID INPUT

ALGORITHM:

Step 1: Start
Step 2: Accept a sentence terminated by '.', '?', or '!' from the user.
Step 3: Iterate through the sentence to reduce extra blank spaces between words to a
single blank space.
Step 4: Initialize a new string 'processedSentence' to store the modified sentence.
Step 5: Iterate through each character in the input sentence.
Step 6: If the current character is not a blank space or the previous character was not a
blank space, append it to 'processedSentence'.
Step 7: Accept a word from the user along with its position number.
Step 8: Tokenize the processed sentence into words.
Step 9: Initialize a counter variable to keep track of the position number of words.
Step 10: Iterate through each word in the tokenized sentence.
Step 11: If the current word matches the user-provided word and its position matches the
input position, skip appending this word.
Step 12: Otherwise, append the word to a new string 'modifiedSentence' with proper
spacing.
Step 13: Display the modified sentence 'modifiedSentence'.
Step 14: End.

33
PROGRAM

import java.util.*;

class word_delete {
public static void main() {
int i = 0, count = 1, len = 0, pos = 0;
char ch = ' ', last = ' ';
String sen = "", newsen = "", wd = "", wd1 = "";
Scanner sc = new Scanner(System.in);
System.out.print("ENTER A SENTENCE: ");
sen = sc.nextLine(); //input sentence
len = sen.length();
last = sen.charAt(len - 1);
if (last != '.' && last != '?' && last != '!') { //if does not end in . or ?
System.out.println("INVALID INPUT.");
System.exit(0);
}
sen = sen.toUpperCase(); //converting to uppercase

System.out.print("WORD TO BE DELETED: ");


wd = sc.next();
wd = wd.toUpperCase();
System.out.print("WORD POSITION IN THE SENTENCE: ");
pos = sc.nextInt(); //position of word to be deleted
for (i = 0; i < len; i++) {
ch = sen.charAt(i);
if (ch == ' ' || ch == '.' || ch == '?' || ch == '!') {
if (wd1.equals(wd) == true && (count) == pos) { //word to be deleted

} else {
newsen = newsen + wd1 + ch; //not the word to be deleted
}
wd1 = "";
count++;
} else {
wd1 = wd1 + ch;
}
}
System.out.println("OUTPUT:" + newsen); //printing after deleting word
}
}

34
VARIABLE DESCRIPTION TABLE

Variable Data Type Description


i int A loop counter for iterating over the sentence.
count int A counter for the number of words in the sentence.
len int The length of the sentence.
pos int The position of the word to be deleted in the sentence.
ch char A variable used to store the current character in the sentence.
last char The last character in the sentence.
sen String The input sentence.
newsen String The output sentence after deleting the word.
wd String The word to be deleted.
wd1 String A variable used to store the current word being processed.

OUTPUT
ENTER A SENTENCE: A MORNING WALK IS GOOD FOR YOUR HEALTH.
WORD TO BE DELETED: WALK
WORD POSITION IN THE SENTENCE: 3
OUTPUT: A MORNING IS GOOD FOR YOUR HEALTH.

35
Question 10
An ISBN ( International Standard Book Number) is a ten digit code which uniquely
identifies a book. The first nine digits represent the Group, Publisher and Title of the book
and the last digit is used to check whether ISBN is correct or not.
Each of the first nine digits of the code can take a value between 0 and 9. Sometimes it is
necessary to make the last digit equal to ten; this is done by writing the last digit of the code
as X. To verify an ISBN, calculate 10 times the first digit, plus 9 times the second digit, plus
8 times the third and so on until we add 1 time the last digit. If the final number leaves no
remainder when divided by 11, the code is a valid ISBN.
For example:
1. 02011003311 = 10 x 0 + 9 x 2 + 8 x 0 + 7 x 1 + 6 x 1 + 5 x 0 + 4 x 3 + 3 x 3 + 2 x 1 + 1 x 1 = 55
Since 55 leaves no remainder when divisible by 11, hence it is a valid ISBN.
2. 007462542X = 10 x 0 + 9 x 0 + 8 x 7 + 7 x 4 + 6 x 6 + 5 x 2 + 4 x 5 + 3 x 4 + 2 x 2 + 1 x
10 = 176 Since 176 leaves no remainder when divided by 11, hence it is a valid ISBN.
3. 0112112425 = 10 x 0 + 9 x 1 + 8 x 1 + 7 x 2 + 6 x 1 + 5 x 1 + 4 x 1 + 3 x 4 + 2 x 2 + 1 x
5 = 71 Since 71 leaves no remainder when divided by 11, hence it is not a valid ISBN.
Design a program to accept a ten digit code from the user. For an invalid input, display an
appropriate message. Verify the code for its validity in the format specified below:
Test your program with sample data and some random data.
Example 1
INPUT CODE: 0201530821
OUTPUT : SUM = 99
LEAVES NO REMAINDER – VALID ISBN CODE
Example 2
INPUT CODE: 035680324
OUTPUT : INVALID INPUT
Example 3
INPUT CODE: 0231428031
OUTPUT : SUM = 122
LEAVES REMAINDER – INVALID ISBN CODE

ALGORITHM
Step 1: Start
Step 2: Accept a ten-digit ISBN code from the user.
Step 3: Initialize a variable 'sum' to 0.
Step 4: Iterate through each digit of the ISBN from left to right.
Step 5: Multiply the current digit by its position (10 for the first digit, 9 for the second,
and so on).
Step 6: Add the result to the 'sum'.
Step 7: If the last digit is 'X', treat it as 10 and add it to the 'sum'.
Step 8: Check if the 'sum' is divisible by 11.
Step 9: If yes, display a message indicating that the ISBN is valid.
Step 10: If no, display a message indicating that the ISBN is not valid.
Step 11: End.

36
PROGRAM

import java.util.*;
public class ISBNnumber {
public static void main() {
Scanner in = new Scanner(System.in);
System.out.print("Enter the ISBN: ");
long isbn = in.nextLong();

int sum = 0, count = 0;


long t = isbn;
while (t != 0) {
t = t / 10;
count++;
}
if (count != 10)
if (count != 9) {
System.out.println("INVALID INPUT" + count); //not equal to 10 digits
System.exit(0);

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


int d = (int)(isbn % 10); //extracting digits
sum += d * i; //sum of digits
isbn /= 10;
}

if (sum % 11 == 0) { //sum divisible by 11, number is a valid isbn no.


System.out.println("Sum = " + sum + "\nLEAVES NO REMAINDER – VALID
ISBN CODE");
} else {
System.out.println("Sum = " + sum + "\nLEAVES REMAINDER – INVALID ISBN
CODE");
}
}
}

37
VARIABLE DESCRIPTION TABLE

Variable Data Type Description


isbn long The ISBN number to be validated.
sum int The sum of the digits of the ISBN number.
count int The number of digits in the ISBN number.
A temporary variable used to count the number of digits in the
t long ISBN number.
i int A loop counter for iterating over the digits of the ISBN number.
d int A variable used to store the current digit of the ISBN number.

OUTPUT
Enter the ISBN: 018224012
INVALID INPUT8
Enter the ISBN: 1234567890
Sum = 210
LEAVES REMAINDER – INVALID ISBN CODE
Enter the ISBN: 0201530821
Sum = 99
LEAVES NO REMAINDER – VALID ISBN CODE

38
Question 11
Write a program to declare a square matrix A[][] of order (M X M) where 'M' is the number
of rows and the number of columns such that M must be greater than 2 and less than 20.
Allow the user to input integers into this matrix. Display appropriate error message for an
invalid input. Perform the following tasks:
1. Display the input matrix.
2. Create a mirror image of the inputted matrix.
3. Display the mirror image matrix.
Test your program for the following data and some random data:
Example 1
INPUT : M = 3
4 16 12
8 2 14
4 1 3
OUTPUT :
ORIGINAL MATRIX
4 16 12
8 2 14
4 1 3
MIRROR IMAGE MATRIX
12 16 4
14 2 8
3 1 6
Example 2
INPUT : M = 22
OUTPUT : SIZE OUT OF RANGE
ALGORITHM

Step 1: Start
Step 2: Accept a positive integer 'M' from the user.
Step 3: Check if 'M' is greater than 2 and less than 20. If not, display an error message
and end the program.
Step 4: Declare a square matrix A[][] of order (M x M).
Step 5: Allow the user to input integers into the matrix A[][].
Step 6: Display the input matrix A[][].
Step 7: Initialize a new matrix 'mirrorMatrix' of the same order as A[][].
Step 8: Create a mirror image of the input matrix:
STEP 9: Iterate through each element of the matrix A[][].
STEP 10: Assign the element at the current position to the corresponding position in
'mirrorMatrix', but mirrored along the vertical axis.
Step 11: Display the mirror image matrix 'mirrorMatrix'.
Step 12: End.

PROGRAM

import java.util.*;
39
class mirrormat
{
public static void main() {

int M, i, j, k, t;

Scanner sc = new Scanner(System.in);


System.out.println("Enter no of rows for a square matrix: ");
M = sc.nextInt();

if (M <= 2 || M >= 20) {


System.out.println("\nSIZE OUT OF RANGE");
} else {

int A[][] = new int[M][M]; //initializing matrix

System.out.println("Enter elements: ");


for (i = 0; i < M; i++) {
for (j = 0; j < M; j++) {
A[i][j] = sc.nextInt(); //inputting matrix
}
}

System.out.println("ORIGINAL MATRIX");
for (i = 0; i < M; i++) {
for (j = 0; j < M; j++) {
System.out.print(A[i][j] + " "); //printing original matrix
}
System.out.println();
}

for (j = 0, k = M - 1; j < M / 2; j++, k--) {

for (i = 0; i < M; i++) { // mirroring the matrix

t = A[i][j];
A[i][j] = A[i][k];
A[i][k] = t;

}
}

System.out.println("MIRRORED MATRIX");
for (i = 0; i < M; i++) {
for (j = 0; j < M; j++) {
System.out.print(A[i][j] + " "); //printing the mirrored matrix

40
}
System.out.println();
}
} }
}

VARIABLE DESCRIPTION TABLE

Variable Data Type Description


M int The number of rows and columns in the square matrix.
i int A loop counter for iterating over the rows of the matrix.
j int A loop counter for iterating over the columns of the matrix.
A loop counter for iterating over the columns of the matrix in
k int reverse order.
t int A temporary variable used to store the value of a matrix element.
A int[][] A 2D array representing the square matrix.

OUTPUT

Enter no of rows for a square matrix:


3
Enter elements:
234
1
246
3679
364
78
796
674

7895

ORIGINAL MATRIX
234 1 246
3679 364 78
796 674 7895

MIRRORED MATRIX
246 1 234
78 364 3679
7895 674 796

41
Question 12
A palindrome is a word that may be read the same way in either direction. Accept a sentence
in UPPER CASE which is terminated by either ".", "?", or "!". Each word of the sentence is
separated by a single blank space.
Perform the following tasks:
1. Display the count of palindromic words in the sentence.
2. Display the palindromic words in the sentence.
Example of palindromic words:
MADAM, ARORA, NOON
Test your program with the sample data and some random data:
Example 1
INPUT : MOM AND DAD ARE COMING AT NOON.
OUTPUT : MOM DAD NOON
NUMBER OF PALINDROMIC WORDS : 3
Example 2
INPUT : NITIN ARORA USES LIRIL SOAP.
OUTPUT : NITIN ARORA LIRIL
NUMBER OF PALINDROMIC WORDS : 3
Example 3
INPUT : HOW ARE YOU?
OUTPUT : NO PALINDROMIC WORDS

ALGORITHM
Step 1: Start
Step 2: Accept a sentence in UPPER CASE terminated by ".", "?", or "!" from the user.
Step 3: Tokenize the sentence into words using a single blank space as a separator.
Step 4: Initialize variables for counting palindromic words and storing palindromic
words.
Step 5: Iterate through each word in the tokenized sentence.
STEP 6: Check if the current word is a palindrome:
STEP 7: Initialize two pointers, one at the beginning and one at the end of the current
word.
STEP 8: Compare characters at the pointers.
STEP 9: If characters are not equal, the word is not a palindrome; otherwise, continue
comparing until the pointers meet.
STEP 10: If pointers meet, add the word to the list of palindromic words and increment
the count.
Step 11: Display the count of palindromic words.
Step 12: Display the palindromic words.
Step 13: End.

42
PROGRAM

import java.util.*;
class Palindromic {
boolean isPalindrome(String str) {
String rev = "";
boolean f = false;

for (int i = str.length() - 1; i >= 0; i--) { //reversing the string


rev = rev + str.charAt(i);
}

if (str.equals(rev)) { //checking if string after reverse is same as before


f = true;
}
return f;
}
public static void main() {
Palindromic obj = new Palindromic();
String a, w = "";
int c = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter sentence ");
a = sc.nextLine();
char last = a.charAt(a.length() - 1);
if (last != '.' && last != '?' && last != '!') {
System.out.println("INVALID INPUT.");
System.exit(0);
}
a = a.substring(0, a.length() - 1); //removing the special character at the end

StringTokenizer st = new StringTokenizer(a);


int n = st.countTokens();
for (int i = 0; i < n; i++) {
w = st.nextToken(); //extracting word off the sentence
if (obj.isPalindrome(w)) { // checking for palindrome
System.out.print(w + " ");
c++;

}
}
if (c == 0) { //no palindrome words found
System.out.print(" NO PALINDROMIC WORDS");

} else {
System.out.println("\nNUMBER OF PALINDROMIC WORDS : " + c);
43
}
}
}

VARIABLE DESCRIPTION TABLE


Variable DataType Description
str String The string to be checked for palindrome
rev String The reversed string
f boolean Flag to indicate whether the string is a palindrome
i int Loop counter
a String The input sentence
w String A word extracted from the input sentence
c int Counter for the number of palindromic words found
st StringTokenizer StringTokenizer object for splitting the input sentence into words
n int Number of words in the input sentence

OUTPUT

Enter sentence
The radar was placed at a low level
INVALID INPUT.
Enter sentence
The radar was placed at a low level.
radar a level
NUMBER OF PALINDROMIC WORDS : 3

44
Question 13
A prime palindrome integer is a positive integer (without leading zeros) 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 in the
format specified below:
Test your program with the sample data and some random data:
Example 1
INPUT:
m=100
n = 1000
OUTPUT:
THE PRIME PALINDROME INTEGERS ARE:
101, 131, 151, 181, 191, 313, 353, 373, 383, 727, 757, 787, 797, 919, 929
FREQUENCY OF PRIME PALINDROME INTEGERS : 15
Example 2
INPUT:
m = 100
n = 5000
OUTPUT: OUT OF RANGE

ALGORITHM

Step 1: Start
Step 2: Accept two positive integers m and n from the user where m < 3000 and n <
3000.
Step 3: Initialize a variable 'count' to 0 to store the count of prime palindrome integers.
Step 4: Iterate through the range [m, n].
STEP 5: Check if the current number is a prime palindrome:
STEP 6: Check if the number is prime using a prime-checking function.
STEP 7: Initialize a variable 'isPrime' to true.
STEP 8: Iterate from 2 to the square root of the number.
STEP 9: If the number is divisible by any of these values, set 'isPrime' to false and break
from the loop.
STEP 10: If 'isPrime' is still true, the number is prime.
STEP 11: Check if the number is a palindrome using a palindrome-checking function.
STEP 12: Convert the number to a string.
STEP 13: Initialize two pointers, one at the beginning and one at the end of the string
representation.
STEP 14: Compare characters at the pointers.
STEP 15: If characters are not equal, the number is not a palindrome; otherwise, continue
comparing until the pointers meet.
STEP 16: If pointers meet, the number is a palindrome.

45
STEP 17: If the number is both prime and a palindrome, increment 'count' and display the
number.
Step 18: Display the count of prime palindrome integers.
Step 19: End.

PROGRAM
import java.util.*;
class primepalindrome
{
public static void main()
{
Scanner sc = new Scanner(System.in);

int m, n, i, j, t, c, r, a, freq;

System.out.println("Enter two positive integers m and n( m< 3000 and n < 3000): ");
m = sc.nextInt();
n = sc.nextInt();

if (m < 3000 && n < 3000) {

freq = 0;

System.out.println("The prime palindrome integers are:");


for (i = m; i <= n; i++) { // checking integers from m to n

t = i;

c = 0;
for (j = 1; j <= t; j++) { //checkimg for prime
if (t % j == 0)
c++;
}
if (c == 2) {

r = 0;
while (t > 0) {
a = t % 10;
r = r * 10 + a; //reversing the integer
t = t / 10;
}
if (r == i) { // checking for palindrome
System.out.print(i + " "); //printing prime palindrome number
freq++;
}
}
46
}
System.out.println("\nFrequency of prime palindrome integers:" + freq);
} else {
System.out.println("OUT OF RANGE");
}
}
}

VARIABLE DESCRIPTION TABLE


Variable DataType Description
m int Lower limit of the range to check for prime palindrome integers
n int Upper limit of the range to check for prime palindrome integers
i int Loop counter for the range of integers to check
j int Loop counter for checking if an integer is prime
t int Temporary variable for storing an integer
c int Counter for the number of factors of an integer
r int Reversed integer
a int Digit of an integer
freq int Counter for the number of prime palindrome integers found

OUTPUT

Enter two positive integers m and n( m< 3000 and n < 3000):
110
250
The prime palindrome integers are:
131 151 181 191
Frequency of prime palindrome integers :4

47
Question 14
Write a program to accept a sentence as input. The words in the string are to be separated by
a blank. Each word must be in upper case. The sentence is terminated by either '.','!' or '?'.
Perform the following tasks:
1. Obtain the length of the sentence (measured in words)
2. Arrange the sentence in alphabetical order of the words.
Test your program with the sample data and some random data:
Example 1:
INPUT: NECESSITY IS THE MOTHER OF INVENTION.
OUTPUT:
Length: 6
Rearranged Sentence:
INVENTION IS MOTHER NECESSITY OF THE
Example 2:
INPUT: BE GOOD TO OTHERS.
OUTPUT:
Length: 4
Rearranged Sentence: BE GOOD OTHERS TO

ALGORITHM

Step 1: Start
Step 2: Accept a sentence terminated by '.', '!', or '?' from the user. Ensure each word is in
upper case.
Step 3: Tokenize the sentence into words using a blank space as a separator.
Step 4: Obtain the length of the sentence (number of words) by counting the tokens.
STEP 5: Initialize a variable 'length' to 0.
STEP 6: Iterate through each word in the tokenized sentence and increment 'length' for
each word.
Step 7: Display the length of the sentence.
Step 8: Arrange the sentence in alphabetical order:
STEP 9: Create an array or list to store the words.
STEP 10: Iterate through each word in the tokenized sentence and add it to the array.
STEP 11: Sort the array in alphabetical order.
STEP 12: Display the sentence in alphabetical order.
Step 13: End.

PROGRAM

import java.util.*;
class alphabetical
{
public static void main() {
Scanner sc = new Scanner(System.in);
int i, j, l, p, x, now;
48
String str, word, temp;
char ch;

System.out.println("Enter a sentence in Uppercase");


str = sc.nextLine();
str.toUpperCase(); //converting to uppercase
l = str.length();

now = 0;
char last = str.charAt(str.length() - 1);
if (last != '.' && last != '?' && last != '!') {
System.out.println("INVALID INPUT.");
System.exit(0);
}
for (i = 0; i < l; i++) {
ch = str.charAt(i);
if (ch == ' ' || ch == '?' || ch == '.' || ch == '!')
now++; //counting number of tokens
}

String words[] = new String[now];

x = 0;
p = 0;

for (i = 0; i < l; i++) {


ch = str.charAt(i);
if (ch == ' ' || ch == '?' || ch == '.' || ch == '!') {
word = str.substring(p, i);
words[x++] = word;
p = i + 1;
}
}
//arranging in alphabetical order
for (i = 1; i < x; i++) {
for (j = 0; j < x - i; j++) {
if (words[j].compareTo(words[j + 1]) > 0) {
temp = words[j];
words[j] = words[j + 1];
words[j + 1] = temp;
}
}
}

System.out.println("Length: " + now);


System.out.println("Rearranged sentence: ");
49
for (i = 0; i < x; i++) {
System.out.print(words[i] + " ");
}
}
}

VARIABLE DESCRIPTION TABLE


Variable DataType Description
str String The input sentence in uppercase
i int Loop counter
j int Loop counter
l int Length of the input sentence
p int Pointer to the beginning of the current word
x int Counter for the number of words in the input sentence
words String[] Array to store the words in the input sentence
now int Counter for the number of tokens in the input sentence
last char The last character of the input sentence
ch char The current character in the input sentence
word String The current word in the input sentence
temp String Temporary variable for swapping words

OUTPUT

Enter a sentence in Uppercase


A FRIEND IN NEED IS A FRIEND INDEED.
Length: 8
Rearranged sentence:
A A FRIEND FRIEND IN INDEED IS NEED

50
Question 15
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 both M and N must be greater than 2 and less
than 20. Allow the user to input integers into this matrix.
Perform the following tasks on the matrix:
1. Display the input matrix
2. Find the maximum and minimum value in the matrix and display them along with their position.
3. Sort the elements of the matrix in ascending order using any standard sorting technique and
rearrange them in the matrix.
Output the rearranged matrix.
Example 1
INPUT:
M=3
N=4
Entered values: 8,7,9,3,-2,0,4,5,1,3,6,-4
OUTPUT:
Original matrix:
8 7 9 3
-2 0 4 5
1 3 6 -4
Largest Number: 9
Row: 0
Column: 2
Smallest Number: -4
Row=2
Column=3
Rearranged matrix:
-4 -2 0 1
3 3 4 5
6 7 8 9

ALGORITHM

Step 1: Start
Step 2: Accept two positive integers 'M' and 'N' from the user where both M and N are
greater than 2 and less than 20.
Step 3: Declare a matrix A[][] of order (M x N).
Step 4: Allow the user to input integers into the matrix A[][].
Step 5: Display the input matrix A[][].
Step 6: Find the maximum and minimum values in the matrix:
STEP 7: Initialize variables 'maxValue', 'minValue', 'maxRow', and 'maxColumn' to store
maximum and minimum values along with their positions.
STEP 8: Iterate through each element of the matrix.
STEP 9: Compare the current element with 'maxValue' and 'minValue'.
STEP 10: Update 'maxValue', 'minValue', 'maxRow', and 'maxColumn' if needed.
STEP 11: Display the maximum and minimum values along with their positions.
Step 12: Sort the elements of the matrix in ascending order:
STEP 13: Flatten the matrix into a 1D array.
51
STEP 14: Use any standard sorting technique to sort the 1D array in ascending order.
STEP 15: Rearrange the sorted elements back into the matrix A[][].
Step 16: Display the matrix A[][] after sorting.
Step 17: End.

PROGRAM

import java.util.*;
class maxminsort {
public static void main() {
Scanner scan = new Scanner(System.in);

int m,n,i,j,x,t,min,rowS,colS,max,rowL,colL;

System.out.println("Enter number of rows and columns (2 < number < 20): ");
m = scan.nextInt();
n = scan.nextInt();
if (m > 2 && m < 20 && n > 2 && n < 20) {

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

System.out.println("Enter elements: ");


for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {

a[i][j] = scan.nextInt(); //inputting matrix


}
}
System.out.println("Original Matrix: ");
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
System.out.print(a[i][j] + " "); //printing original matrix
}
System.out.println();
}

min = a[0][0];
max = a[0][0];
rowS = colS = rowL = colL = 0;

int b[] = new int[m * n];


x = 0;

for (i = 0; i < m; i++) {


for (j = 0; j < n; j++) {

52
b[x++] = a[i][j];
//finding minimum value
if (min > a[i][j]) {
min = a[i][j];
rowS = i;
colS = j;
} //finding maximum value
if (max < a[i][j]) {
max = a[i][j];
rowL = i;
colL = j;
}
}
}
//rearranging matrix
for (i = 1; i < x; i++) {
for (j = 0; j < x - i; j++) {

if (b[j] >b[j + 1]) {


t = b[j];
b[j] = b[j + 1];
b[j + 1] = t;
}
}
}

x = 0;
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
a[i][j] = b[x++];
}
}

System.out.println("\nMaximum value: " + max);


System.out.println("Row: " + rowL);
System.out.println("Column: " + colL);
System.out.println("Minimum value: " + min);
System.out.println("Row: " + rowS);
System.out.println("Column: " + colS);
System.out.println("Rearranged Matrix: ");
//printing rearranged matrix
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
System.out.print(a[i][j] + " ");
}
53
System.out.println();
}

} else {
System.out.println("Invalid value");
}
}
}

VARIABLE DESCRIPTION TABLE


Variable DataType Description
m int Number of rows in the matrix
n int Number of columns in the matrix
i int Loop counter for the rows of the matrix
j int Loop counter for the columns of the matrix
x int Loop counter for the rearranged matrix
t int Temporary variable for swapping values
min int Minimum value in the matrix
rowS int Row index of the minimum value
colS int Column index of the minimum value
max int Maximum value in the matrix
rowL int Row index of the maximum value
colL int Column index of the maximum value
a int[][] Original matrix
b int[] Reagrranged matrix

OUTPUT

Enter number of rows and columns (2 < number < 20):


4
5
Enter elements:
375
35375
2354
679
354
08
346
78
32
879
352
769
83
35

54
4
37777
3467
23
865
235
Original Matrix:
375 35375 2354 679 354
8 346 78 32 879
352 769 83 35 4
37777 3467 23 865 235

Maximum value: 37777


Row: 3
Column: 0
Minimum value: 4
Row: 2
Column: 4
Rearranged Matrix:

4 8 23 32 35
78 83 235 346 352
354 375 679 769 865
879 2354 3467 35375 37777

55
Question 16
Write a program to input a natural number less than 1000 and display it in words. Test your
program on the sample data and some random data.
Sample input and output of the program
Examples
Input: 29
Output: TWENTY NINE
Input: 17001
Output: OUT OF RANGE
Input: 119
Output: ONE HUNDRED AND NINETEEN
Input: 500
Output: FIVE HUNDRED

ALGORITHM

Step 1: Start
Step 2: Accept a natural number 'num' from the user, ensuring it is less than 1000.
Step 3: Check if 'num' is greater than or equal to 1000. If yes, display an error message
and end the program.
Step 4: Define arrays or lists to store words for the units, tens, and special cases (e.g.,
teens).
Step 5: Divide 'num' into hundreds, tens, and units places.
STEP 6: Calculate the hundreds place, tens place, and units place separately.
Step 7: Convert each place value into words using the defined arrays or lists.
Step 8: Construct the final word representation of the number.
STEP 9: If the number is greater than 99, append the word for hundreds place.
STEP 10: If the tens‟ place is 1, append the word for teens (special cases).
STEP 11: If the tens place is greater than 1, append the word for tens place.
STEP 12: If the units place is greater than 0, append the word for units place.
Step 13: Display the word representation of the number.
Step 14: End.

PROGRAM
import java.util.*;
class number {
public static void main() {

Scanner sc = new Scanner(System.in);

int n;

System.out.println("Enter a number less than 1000");


n = sc.nextInt();
String result = "";
56
if (n >= 1000) {
System.out.println("OUT OF RANGE");
} else {
String h = "", t = "", o = "";
int a, b, c;
//storing nomenclature of numbers in ones i.e <10, teens i.e 10-19 and tens
String ones[] = {"one","two","three","four","five","six","seven","eight","nine"};
String teens[] =
{"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","ninet
een"};
String tens[] =
{"ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
a = n / 100;
if (n > 100) { //number in hundreds
n = n % 100; }
b = n / 10;
c = n % 10;
if (a != 0) {
h = ones[a - 1] + " hundred";
}
if (b == 0 &&c != 0) {
o = ones[c - 1];
} else if (c == 0 &&b != 0) {
t = tens[b - 1];
} else if (b == 1) {
t = teens[c - 1];
} else if (b != 0 && c != 0) {
t = tens[b - 1] + " " + ones[c - 1];
}
if (b == 0 && c == 0)
result = h;
else if (a == 0)
result = t + " " + o;
else
result = h + " and " + t + " " + o;

System.out.println(result.toUpperCase()); //printing in upper case

}
}//main
}//class

57
VARIABLE DESCRIPTION TABLE
Variable DataType Description
n int The input number
result String The string representation of the input number in words
h String The hundreds part of the input number in words
t String The tens part of the input number in words
o String The ones part of the input number in words
a int The hundreds digit of the input number
b int The tens digit of the input number
c int The ones digit of the input number
ones String[] Array of strings containing the names of the ones digits
teens String[] Array of strings containing the names of the teen numbers
tens String[] Array of strings containing the names of the tens digits

OUTPUT

Enter a number less than 1000


456
FOUR HUNDRED AND FIFTY SIX
Enter a number less than 1000
6780
OUT OF RANGE

58
Question 17
Encryption is a technique of coding messages to maintain their secrecy. A String array of
size 'n' where 'n' is greater than 1 and less than 10, stores single sentences (each sentence
ends with a full stop) in each row of the array.
Write a program to accept the size of the array.

Display an appropriate message if the size is not satisfying the given condition.
Define a string array of the inputted size and fill it with sentences row-wise. Change the
sentence of the odd rows with an encryption of two characters ahead of the original
character.
Also change the sentence of the even rows by storing the sentence in reverse order. Display
the encrypted sentences as per the sample data given below.
Test your program on the sample data and some random data.
Example 1
INPUT: n = 4
IT IS CLOUDY.
IT MAY RAIN.
THE WEATHER IS FINE.
IT IS COOL.
OUTPUT:
KV KU ENQWFA.
RAIN MAY IT.
VJG YGCVJGT KU HKPG.
COOL IS IT.

ALGORITHM
Step 1: Start
Step 2: Accept an integer 'n' as the size of the array from the user, ensuring it is greater
than 1 and less than 10.
Step 3: Check if 'n' satisfies the given conditions. If not, display an error message and end
the program.
Step 4: Declare a String array 'sentences' of size 'n'.
Step 5: Iterate through each row of the 'sentences' array and accept a sentence for each
row.
STEP 6: For odd rows, encrypt the sentence by shifting each character two positions
ahead.
STEP 7: Initialize a new empty string 'encryptedSentence'.
STEP 8: Iterate through each character in the sentence.
STEP 9: Shift the character two positions ahead and append it to 'encryptedSentence'.
STEP 10: Store 'encryptedSentence' in the corresponding row of the 'sentences' array.
STEP 11: For even rows, reverse the sentence.
STEP 12: Initialize a new empty string 'reversedSentence'.
STEP 13: Iterate through each character in the sentence in reverse order.
STEP 14: Append the character to 'reversedSentence'.
STEP 15: Store 'reversedSentence' in the corresponding row of the 'sentences' array.
Step 16: Display the encrypted sentences in the 'sentences' array.
59
Step 17: End.
PROGRAM

import java.util. * ;
class encrysen {
String input() {
Scanner sc = new Scanner(System. in );
return sc.nextLine();
}
void encrypt(String s) {
int i,len;
char ch;
String st = "";
len = s.length();
for (i = 0; i < len; i++) {
ch = s.charAt(i);
if ((ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122)) {
ch = (char)(ch + 2); //shifting character to +2 of it ASCII
if (ch > 90 && ch < 97) {
ch = (char)((64 + ch - 90));
}
else if (ch > 122) {
ch = (char)((96 + ch - 122));
}
}
st = st + ch; //adding to the string
}
System.out.println(st);
}
void reverse(String s) {
s = s.trim();
s = s.substring(0, s.length() - 1);
int i;
String t = "";
StringTokenizer st = new StringTokenizer(s);
int n = st.countTokens();
for (i = 0; i < n; i++) { //reversing the inputted string
String c = st.nextToken();
t = c + " " + t;
}
System.out.println(t + ".");
}
public static void main() {
encrysen obj = new encrysen();
String str[],s;
60
int i,n;
Scanner sc = new Scanner(System. in );

System.out.println("Enter number of sentences:");


n = sc.nextInt();
if (n < 2 || n > 9) {
System.out.println("INVALID ENTRY:");
System.exit(0);
}
str = new String[n];
System.out.println("Enter sentences");
for (i = 0; i < n; i++) {
str[i] = obj.input();
}
for (i = 0; i < n; i++) {
s = str[i];
if ((i + 1) % 2 == 0) obj.encrypt(s); /if at odd numbered position
else obj.reverse(s); //if at even numbered position
}
}
}
VARIABLE DESCRIPTION TABLE
Variable DataType Description
input() String A method that takes input from the user and returns it as a string.
str[] String[] An array of strings to store the input sentences.
s String A variable to store the current sentence being processed.
i int A loop counter.
n int The number of sentences to be processed.
ch char A variable to store the current character being processed.
st String A variable to store the encrypted string.
t String A variable to store the reversed string.
st StringTokenizer A StringTokenizer object to split the string into words.
n int The number of words in the string.
c String A variable to store the current word being processed.

61
OUTPUT
Enter number of sentences:
5
Enter sentences
IT IS A GOOD DAY.
IT MIGHT RAIN TOMMOROW.
SCHOOL WAS CLOSED YESTERDAY.
WE HAVE FINISH PROJECTS BEFORE DEADLINE.
TECHNOLOGY IS EXPONENTIALLY EXPANDING EVERYDAY.
DAY GOOD A IS IT .
KV OKIJV TCKP VQOOQTQY.
YESTERDAY CLOSED WAS SCHOOL .
YG JCXG HKPKUJ RTQLGEVU DGHQTG FGCFNKPG.
EVERYDAY EXPANDING EXPONENTIALLY IS TECHNOLOGY .

62
Question 18
Design a program which accepts your date of birth in dd mm yyyy format. Check whether
the date entered is valid or not.
If it is valid, display "VALID DATE", also compute and display the day number of the year
for the date of birth. If it is invalid, display "INVALID DATE" and then terminate the
program.
Testing of the program
Example 1
INPUT: Enter your date of birth in dd mm yyyy format
05
01
2010
OUTPUT: VALID DATE
5
Example 2
INPUT: Enter your date of birth in dd mm yyyy format
03
04
2010
OUTPUT: VALID DATE
93
Example 3
INPUT: Enter your date of birth in dd mm yyyy format
34
06
2010
OUTPUT: INVALID DATE

ALGORITHM

Step 1: Start
Step 2: Accept the date of birth in dd mm yyyy format from the user.
Step 3: Extract the day, month, and year components from the input.
Step 4: Check if the day, month, and year are valid.
STEP 5: Check if the month is between 1 and 12.
STEP 6: Check if the day is valid for the given month (considering leap years for
February).
STEP 7: Check if the year is a valid positive integer.
STEP 8: If any of the conditions in Steps 5-7 fails, display "INVALID DATE" and
terminate the program.
Step 9: Calculate the day number of the year.
STEP 10: Initialize an array 'daysInMonth' to store the number of days in each month.
STEP 11: Calculate the day number by summing the days of the months preceding the
given month and adding the day.
Step 12: Display "VALID DATE".
Step 13: Display the calculated day number.
Step 14: End.
63
PROGRAM

import java.util.*;
class DOB {
public static void main() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your date of birth in dd_mm_yyyy format : ");
int d = sc.nextInt();
int m = sc.nextInt();
int y = sc.nextInt();
int dom[] = {31,28,31,30,31,30,31,31,30,31,30,31}; //number of days in months
if (y % 400 == 0 || (y % 100 != 0 && y % 4 == 0)) //if leap year
dom[1] = 29; //29 days in february in leap year
if (d <= dom[m - 1]) {
System.out.println("VALID DATE ");
int i, s = 0;
for (i = 0; i < m - 1; i++)
s = s + dom[i];

s += d; //finding number of days

System.out.print(s);
} else {
System.out.println("INVALID DATE");
}
}//main
}//class

VARIABLE DESCRIPTION TABLE


Variable DataType Description
d int Day
m int Month
y int Year
dom int[] Array of integers representing the number of days in each month
s int Number of days since the beginning of the year
i int Loop counter

OUTPUT

Enter your date of birth in dd_mm_yyyy format :


05
04
2006
VALID DATE
95
64
Question 19
A bank intends to design a program to display the denomination of an input amount, upto 5
digits. The available denominations with the bank are of rupees 1000,500,100,50,20,10,5,2
and 1.
Design a program to accept the amount from the user and display the break-up in descending
order of denominations. (i.e. preference should be given to the highest denomination
available) along with the total number of notes. [Note: only the denomination used should be
displayed]. Also print the amount in words according to the digits.
Example 1
INPUT: 14836
OUTPUT: ONE FOUR EIGHT THREE SIX
DENOMINATION:
1000 X 14 =14000
500 X 1 =500
100 X 3 =300
50 X 1 =50
5 X 1 =5
1 X 1 =1
Example 2
INPUT: 235001
OUTPUT: INVALID AMOUNT

ALGORITHM

Step 1: Start
Step 2: Accept the amount from the user.
Step 3: Check if the amount is a valid positive integer.
STEP 4: If not, display "INVALID AMOUNT" and terminate the program.
Step 5: Convert the amount to words.
STEP 6: Initialize arrays or lists to store the words for each digit.
STEP 7: Iterate through each digit in the amount and append the corresponding word to
the result.
Step 8: Display the amount in words.
Step 9: Determine the denomination breakdown.
STEP 10: Initialize an array 'denominations' with the available denominations [1000,
500, 100, 50, 20, 10, 5, 2, 1].
STEP 11: Iterate through each denomination in 'denominations'.
STEP 12: Calculate the number of notes for the current denomination.
STEP 13: If the number of notes is greater than 0, display the denomination and the
number of notes.
Step 14: End.

PROGRAM

import java.util.*;
class denomination {
65
public static void main() {

Scanner sc = new Scanner(System.in);


int amt;

System.out.print("Enter amount upto 5 digits: ");


amt = sc.nextInt();

if (amt > 99999) {


System.out.println("INVALID AMOUNT.");
} else {
int a[] = {1000, 500,100,50,20,10,5,2,1}; //denominations
int i, p, r, b, t;

p = amt;
String ones[] = {"one","two","three","four","five","six","seven","eight","nine"};
r = 0;
while (p > 0) {
r = r * 10 + p % 10;
p /= 10;
}

while (r > 0) {
b = r % 10;
System.out.print(ones[b - 1].toUpperCase() + " "); //printing name
r /= 10;
}
System.out.println("\nDenomination :"); //printing denominations
for (i = 0; i <a.length; i++) {
t = amt / a[i]; // till amount is divisible by highest denomination
if (t != 0) {
System.out.println(a[i] + "X" + t + "=" + (t * a[i]));
amt = amt % a[i];
}
}

}
}//main
}//class

66
VARIABLE DESCRIPTION TABLE
Variable DataType Description
amt int The amount entered by the user.
a[] int[] Array of denominations
i int Loop counter
p int Temporary variable to store the amount in reverse order
r int Temporary variable to store the reversed amount
b int Temporary variable to store the digit at the current position
Temporary variable to store the number of notes of the current
t int denomination
ones[] String[] Array of strings containing the names of the ones digits

OUTPUT

Enter amount upto 5 digits: 23534


TWO THREE FIVE THREE FOUR
Denomination :
1000X23=23000
500X1=500
20X1=20
10X1=10
2X2=4

67
Question 20
Given the two positive integers p and q, where p < q. Write a program to determine how
many Kaprekar numbers are there in the range between 'p' and 'q'(both inclusive) and output
them.About 'kaprekar' number:
A positive whole number 'n' that has 'd' number of digits is squared and split into 2 pieces, a
right hand piece that has 'd' digits and a left hand piece that has remaining 'd' or 'd-1' digits.
If the sum of the pieces is equal to the number then it's a Kaprekar number.
Example 1
INPUT:
p=1
q=1000
OUTPUT:
THE KAPREKAR NUMBERS ARE:
1,9,45,55,99,297,999
FREQUENCY OF KAPREKAR NUMBERS IS:8

ALGORITHM

Step 1: Start
Step 2: Accept two positive integers p and q from the user, ensuring that p < q.
Step 3: Initialize variables for counting Kaprekar numbers and storing them.
Step 4: Iterate through the range [p, q].
STEP 5: Calculate the square of the current number.
STEP 6: Convert the square to a string to determine the number of digits.
STEP 7: Iterate through each possible split position (from 1 to the number of digits - 1).
STEP 8: Extract the left and right pieces based on the split position.
STEP 9: Convert the left and right pieces to integers.
STEP 10: Check if the sum of the left and right pieces is equal to the original number.
STEP 11: If yes, it is a Kaprekar number. Increment the count and store the number.
Step 12: Display the Kaprekar numbers.
Step 13: Display the frequency of Kaprekar numbers.
Step 14: End.

PROGRAM

import java.util.*;
class kaprekar {
public static void main() {

Scanner scan = new Scanner(System.in);


System.out.println("Enter range : ");
int p = scan.nextInt();
int q = scan.nextInt();

int d, i, n, a, b, s;
int ff = 0;
68
System.out.println("The Kaprekar numbers are : ");
for (i = p; i <= q; i++) {
n = i;
d = 0;

while (n > 0) {
d++;
n /= 10;
}
//finding if a kaprekar number
s = i * i;
a = s % (int) Math.pow(10, d); //first half of the square of number

b = s / (int) Math.pow(10, d); //second half of the square of number


if (a + b == i) {
System.out.print(i + " ");
ff++; //incrementing frequency
}
}
System.out.println("\nFREQUENCY OF KAPREKAR NUMBER IS : " + ff);
}
}

VARIABLE DESCRIPTION TABLE


Variable DataType Description
p int Lower bound of the range.
q int Upper bound of the range.
d int Number of digits in the current number.
i int Loop counter.
n int Current number being processed.
a int First half of the square of the current number.
b int Second half of the square of the current number.
s int Square of the current number.
ff int Frequency of Kaprekar numbers.

OUTPUT

Enter range :
35
100
The Kaprekar numbers are :
45 55 99
FREQUENCY OF KAPREKAR NUMBER IS : 3

69
Question 21
Input a paragraph containing 'n' number of sentences where (1<=n<=4). The words are to be
separated with a single blank space and are in upper case. A sentence may be terminated
either with a full stop (.) or question mark (?).
Perform the following:
1. Enter the number of sentences, if it exceeds the limit show a message.
2. Find the number of words in the paragraph
3. Display the words in ascending order with frequency.
Example 1
INPUT: Enter number of sentences: 1
Enter sentences:
TO BE OR NOT TO BE.
OUTPUT:
Total number of words: 6
WORD FREQUENCY
OR 1
NOT 1
TO 2
BE 2
Example 2
INPUT: Enter number of sentences: 3
Enter sentences:
THIS IS A STRING PROGRAM. IS THIS EASY? YES, IT IS.
OUTPUT:
Total number of words: 11
WORD FREQUENCY
A 1
STRING 1
PROGRAM 1
EASY 1
YES 1
IT 1
THIS 2
IS 3
ALGORITHM
Step 1: Start
Step 2: Accept the number of sentences 'n' from the user, ensuring that 1 <= n <= 4.
STEP 3: If 'n' exceeds the limit, display a message and terminate the program.
Step 4: Initialize a dictionary or map to store word frequencies.
Step 5: Iterate 'n' times to accept each sentence from the user.
Step 6: Tokenize each sentence into words using a single blank space as a separator.
Step 7: Update the word frequencies in the dictionary.
Step 8: Calculate the total number of words in the paragraph.
STEP 9: Iterate through the dictionary to sum the frequencies.
Step 10: Display the total number of words.
Step 11: Display the words in ascending order with their frequencies.
STEP 12: Sort the dictionary based on keys (words).
STEP 13: Display the sorted words along with their frequencies.
70
Step 14: End.
PROGRAM
import java.util.*;
class freqword
{
public static void main() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter number of sentences.");
int n = sc.nextInt();

if (n < 1 || n >4)
{
System.out.println("Invalid Entry");
System.exit(0);
}

System.out.println("Enter sentence");
sc.nextLine();
String S = sc.nextLine();
S = S.toUpperCase();

StringTokenizer st = new StringTokenizer(S, " .?");


int nn = st.countTokens();

System.out.println("Total number of words: " + nn);

String wrdarr[] = new String[nn];


int freq[] = new int[nn];
int idx = 0;

for (int i = 0; i < nn; i++) {

String word = st.nextToken();


int j = 0;

for (j = 0; j < idx; j++) {


if (wrdarr[j].equals(word)) { //finding frequency of the number
freq[j]++;
break;
}
}

if (j == idx) {
wrdarr[idx] = word; //inputting word in the array wrdarr
freq[idx]++; //inputting frequency of that word in array freq
71
idx++;
}
}

for (int i = 0; i < idx - 1; i++) {


for (int j = 0; j < idx - i - 1; j++) {
if (freq[j] >freq[j + 1]) //sorting in descending order according to frequency
{ int t = freq[j];
freq[j] = freq[j+1];
freq[j+1] = t;

String temp = wrdarr[j];


wrdarr[j] = wrdarr[j+1];
wrdarr[j+1] = temp;
}
}
}
//printing the word and its frequency
System.out.println("Word\tFrequency");
for (int i = 0; i < idx; i++) {
System.out.println(wrdarr[i] + "\t" + freq[i]);
}
}
}
VARIABLE DESCRIPTION TABLE
Variable DataType Description
n int Number of sentences.
S String Input sentence.
st StringTokenizer StringTokenizer object for splitting the input sentence into words.
nn int Number of words in the input sentence.
wrdarr[] String[] Array of strings to store the words in the input sentence.
freq[] int[] Array of integers to store the frequency of each word in the input sentence.
idx int Index of the current word in the wrdarr[] array.
word String Current word being processed.
j int Loop counter.
i int Loop counter.
t int Temporary variable used for sorting.
temp String Temporary variable used for sorting.

72
OUTPUT
Enter number of sentences.
3
Enter sentence
TODAY IS A GOOD DAY.
Total number of words: 5
Word Frequency
TODAY 1
IS 1
A 1
GOOD 1
DAY 1

73
Question 22
A class Employee contains employee details and another class Salary calculates the
employee‟s net salary. The details of the two classes are given below.
Class name – Employee
Data Members-:
 empno - to store employee no
 empname - to store employee name
 empdesign – to store designation
Member Functions-:
 Employee( ) - default contructor
 Employee(---) - parameterized constructor
 void display( ) – to display data members with proper message

Class name – Salary


Data Members-:
 basic -to store the basic pay
Member Functions-:
 Salary( ) - default constructor
 Salary(---) - parameterized constructor to initialize data members of both classes
 void calculate( ) - calculates the net salary according to the following rules-:
DA=10% of basic
HRA=15% of basic
Salary=basic+DA+HRA
PF=8% of Salary
Net Salary= Salary-PF

Display the details of the class Employee and the net salary
Specify the class Employee giving the details of the functions using the concept of
inheritance and also specify the class in which object is created and functions are called in
the main function

ALGORITHM

Step 1: Start
Step 2: Define a class named "Employee" with attributes empno (employee number),
empname (employee name), and empdesign (employee designation).
Step 3: Create a constructor for the "Employee" class to initialize empno, empname, and
empdesign to default values.
Step 4: Create another constructor for the "Employee" class with parameters to set
empno, empname, and empdesign to specific values.
Step 5: Implement a method called "display" within the "Employee" class to print the
employee's name, number, and designation.
Step 6: Define a class named "Salary" that inherits from the "Employee" class and has an
additional attribute called "basic."

74
Step 7: Create a constructor for the "Salary" class that takes in parameters for basic,
employee number, employee name, and employee designation. Call the constructor of the
parent class (Employee) using the "super" keyword.
Step 8: Implement a method called "calculate" within the "Salary" class to calculate
various components of an employee's salary, including da (dearness allowance), hra
(house rent allowance), gross pay, pf (provident fund), and net pay. Display these
payment details.
Step 9: In the "calculate" method, calculate da, hra, gross pay, pf, and net pay based on
specific formulas.
Step 10: Print the employee's details (name, number, and designation) by calling the
"display" method from the parent class.
Step 11: Display the payment details, including basic, da, hra, gross pay, and net pay.
Step 12: In the "main" method, create a Scanner object to read input from the user.
Step 13: Prompt the user to enter employee details: name, number, designation, and basic
pay.
Step 14: Read the input values for employee details from the user.
Step 15: Create an instance of the "Salary" class, passing the entered values to the
constructor.
Step 16: Call the "calculate" method on the "Salary" instance to perform salary
calculations and display the results.
Step 17: Stop

PROGRAM
import java.util.*;
class Employee
{
int empno ;String empname , empdesign;
Employee()
{
empno=0;
empname="";
empdesign="";
}
Employee(int a,String b,String c)
{
empno=a;
empname=b;
empdesign=c;
}
void display()
{
System.out.println("Employee name:"+empname);
System.out.println("Employee number:"+empno);
System.out.println("Employee designation:"+empdesign);
75
}
}

class Salary extends Employee //inheriting the base class Employee


{
float basic; //basic salary
Salary(float b,int n,String name,String d)
{
super(n,name,d); //sending constructor parameter to the base class
basic=b;
}
void calculate()
{
double da=0.1*basic;
double hra=0.15*basic; //calculating da
double gross=basic+da+hra; //calculating gross
double pf=0.08*gross //calculating pf
double netpay=gross-pf; //calculating net payable salary
System.out.println("\nEmployee Details");
super.display(); //calling display function of base class
System.out.println("\nPayment Details");
System.out.println("Basic="+basic+"\nDA="+da+"\nHRA="+hra+"\nGross
Pay="+gross+"\nNet Pay="+netpay);
}
public static void main()
{
Scanner sc=new Scanner(System.in);
//inputting parameters and calling all the functions
System.out.print("Enter employee name:");
String name=sc.nextLine ();
System.out.print("Enter employee number:");
int n=sc.nextInt();
System.out.print("Enter employee designation:");
String d=sc.next();
System.out.print("Enter basic pay:");
float b=sc.nextFloat ();
Salary call=new Salary(b,n,name,d);
call.calculate();
}
}

76
VARIABLE DESCRIPTION TABLE
Variable DataType Description
empno int Employee number.
empname String Employee name.
empdesign String Employee designation.
basic float Employee's basic salary.
da double Employee's dearness allowance (DA).
hra double Employee's house rent allowance (HRA).
gross double Employee's gross salary.
pf double Employee's provident fund (PF).
netpay double Employee's net payable salary.
name String Employee name (input from user).
n int Employee number (input from user).
d String Employee designation (input from user).
b float Employee's basic salary (input from user).

OUTPUT

Enter employee name:Anant Shukla


Enter employee number:100230
Enter employee designation:Banker
Enter basic pay:10000

Employee Details-

Employee name:Nakshatra Vidyarthi


Employee number:100230
Employee designation:Banker

Payment Details-

Basic=10000.0
DA=1000.0
HRA=1500.0
Gross Pay=12500.0
Net Pay=11500.0

77
Question 23
Design a class Prime.
Data Members-:
 n - to store the number
Member Functions-:
 Prime(int) - constructor to initialize n
 void check( ) - to check if the no is prime or not by calling a function isPrime(int)
 boolean isPrime(int,int) - returns true/false for prime using recursive technique

ALGORITHM

Step 1: Start
Step 2: Initialize an integer variable n to the user-provided value.
Step 3: Create an instance of the Prime class, passing the value of n as a parameter.
Step 4: Call the check method of the Prime instance.
Step 5: Inside the check method, call the isPrime method with the values n and 2 as
parameters.
Step 6: In the isPrime method:
Check if n is less than or equal to 2:
 If true, proceed to the next step.
 If false, return the result of the following sub-steps:
Check if n is equal to 2:
 If true, return true (indicating n is a prime number).
 If false, return false (indicating n is not a prime number).
Step 7: If n is greater than 2, check if n is divisible by i:
 If it is divisible, return false (indicating n is not a prime number).
 If it is not divisible, proceed to the next step.
Step 8: Check if the square of i is greater than n:
 If true, return true (indicating n is a prime number).
 If false, proceed to the next step.
Step 9: Increment the value of i by 1.
Step 10: Return to step 6 for the next iteration.
Step 11: The result of the isPrime method is returned to the check method.
Step 12: Inside the check method, print a message indicating whether n is a prime
number or not.
Step 13: Stop

78
PROGRAM
import java.util.*;
class Prime
{
int n;
Prime(int nn)
{ n = nn; }
void check()
{
if(isPrime(n,2)) //if true number is prime
{ System.out.println(n+" is a Prime Number."); }
else
{
System.out.println(n+" is NOT a Prime Number.");
} }
boolean isPrime(int n, int i)
{
if (n <= 2)
return (n == 2) ? true : false;
if (n % i == 0) //number is even hence not a prime number
return false;
if (i * i > n) //number is 3, which is prime
return true;
return isPrime(n, i + 1); //recursive parameter to check for prime
}
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter number: ");
int nn = sc.nextInt();
Prime obj = new Prime(nn); //creating an object of the class Prime
obj.check();
}}

VARIABLE DESCRIPTION TABLE


Variable DataType Description
n int The number to be checked for primality.
i int A loop counter used to iterate through the divisors of n.
nn int The number entered by the user.

79
OUTPUT
Enter number:
71
71 is a Prime Number.
Enter number:
12
12 is NOT a Prime Number.

80
Question 24
Design a class Stack-:
Data Members-:
 int arr[ ] – size 50
 int size – store no of elements
 int top
Member Functions-:
 Stack(int s) – to initialize the size by s and top by -1
 void pushvalues(int v) – to fill the stack if it is empty otherwise display message –
“overflow”
 int popvalues() – to delete value from the stack and return it, if possible otherwise
display – “underflow” and return -999
 void display()
 void main()

ALGORITHM

Step 1: Start
Step 2: Initialize an array `arr` of size 50, a variable `size` to store the number of
elements, and a variable `top` to -1.
Step 3: Define a constructor `Stack(int s)` to initialize `size` with `s` and `top` with -1.
Step 4: In the constructor, set `size` to `s`, and `top` to -1.
Step 5: Define a method `pushvalues(int v)`.
Step 6: Check if the stack is not full (`top` is less than `size - 1`).
- If true, increment `top` by 1 and assign the value `v` to `arr` at the `top` index.
- If false, display the message "overflow."
Step 7: Define a method `popvalues()`.
Step 8: Check if the stack is not empty (`top` is greater than or equal to 0).
- If true, retrieve the value at `arr[top]`, decrement `top` by 1, and return the value.
- If false, display the message "underflow" and return -999.
Step 9: Define a method `display()`.
Step 10: Iterate from `i = 0` to `i = top`.
- Display the element `arr[i]`.
Step 11: End

PROGRAM
import java.util.*;
class stack
{
int arr[];
int size;
int top;
stack(int s)
81
{
size=s;
top=-1;
arr = new int[size]; //initializing the stack array
}
void pushvalues(int v)
{
if(top< size-1)
{
arr[++top] = v; //inserting value to the top
}
else
{
System.out.println("Stack overflow"); //stack is full

}
}
int popvalues()
{
int x = -999;
if(top!=-1) //if array is not empty
{
x = arr[top--]; //deleting value from the top of the array
}
return x;
}
void display()
{
if(top==-1)
{
System.out.println("Stack is empty");

}
else //array not empty
{
for(int i=top;i>-1;i--)
{
System.out.println(arr[i]); //printing array elements
} } }
public static void main()
{
Scanner sc = new Scanner(System.in);
int c,n,d;
stack obj = new stack(50);
do
82
{
System.out.println(“PRESS 1 TO PUSH VALUE | PRESS 2 TO POP VALUE |
\n PRESS 3 TO DISPLAY | PRESS 4 TO EXIT”);
System.out.println("Enter your choice");
c= sc.nextInt(); //take the input of user of which function to use
switch(c) //performing the function
{
case 1:
System.out.println("Enter number to insert");
n = sc.nextInt();
obj.pushvalues(n);
break;
case 2:
d = obj.popvalues();
if(d!=-9999)
System.out.println("Deleted value is "+d);
break;
case 3:
obj.display();
break;
case 4:
System.exit(0);
default:
System.out.println("Invalid Choice");
} }
while(c!=4);
}}

VARIABLE DESCRIPTION TABLE


Variable DataType Description
arr[] int[] The stack array.
size int The size of the stack.
top int The index of the top element of the stack.
c int The user's choice of operation.
n int The number to be pushed onto the stack.
d int The number popped from the stack.

83
OUTPUT

PRESS 1 TO PUSH VALUE | PRESS 2 TO POP VALUE |


PRESS 3 TO DISPLAY | PRESS 4 TO EXIT
Enter your choice
1
Enter number to insert
45
PRESS 1 TO PUSH VALUE | PRESS 2 TO POP VALUE |
PRESS 3 TO DISPLAY | PRESS 4 TO EXIT
Enter your choice
1
Enter number to insert
34
PRESS 1 TO PUSH VALUE | PRESS 2 TO POP VALUE |
PRESS 3 TO DISPLAY | PRESS 4 TO EXIT
Enter your choice
2
Deleted value is 34
PRESS 1 TO PUSH VALUE | PRESS 2 TO POP VALUE |
PRESS 3 TO DISPLAY | PRESS 4 TO EXIT
Enter your choice
3
45
PRESS 1 TO PUSH VALUE | PRESS 2 TO POP VALUE |
PRESS 3 TO DISPLAY | PRESS 4 TO EXIT
Enter your choice 4

84
Question 25
Design a class SQ
Data Members-:
 int arr[ ] – max size 100
 int size – store the capacity of arr
 int front
int rear
Member Functions-:
 SQ(int s) – to initialize the size and front and rear by -1
 void addrear(int v) – to add value at rear if possible otherwise display “Queue full at
the rear end… OVERFLOW”
 int deletefront() – to delete value from front if possible otherwise display “Queue
empty…UNDERFLOW”
 void display() – display elements of the queue

ALGORITHM

Step 1: Start
Step 2: Initialize an array `arr` of max size 100, variables `size`, `front`, and `rear` to -1.
Step 3: Define a constructor `SQ(int s)` to initialize `size`, `front`, and `rear` with -1.
Step 4: In the constructor, set `size` to `s`, `front` to -1, and `rear` to -1.
Step 5: Define a method `addrear(int v)`.
Step 6: Check if the queue is not full (the difference between `rear` and `front` is less
than `size - 1`).
- If true, increment `rear` by 1 and assign the value `v` to `arr` at the `rear` index.
- If false, display the message "Queue full at the rear end... OVERFLOW."
Step 7: Define a method `deletefront()`.
Step 8: Check if the queue is not empty (`front` is less than or equal to `rear`).
- If true, retrieve the value at `arr[front]`, increment `front` by 1, and return the value.
- If false, display the message "Queue empty... UNDERFLOW."
Step 9: Define a method `display()`.
Step 10: Iterate from `i = front` to `i = rear`.
- Display the element `arr[i]`.
Step 11: End

PROGRAM
import java.util.*;
class Queue
{
int size = 10;
int front = -1;
int rear = -1;
int que[];
85
public Queue()
{
que = new int[size]; //initializing the array
}

public void addrear(int x)


{
if(rear == size-1)
{
System.out.println("Queue Overflow"); //queue is full
}
else if(front==-1)
{
front++;
rear++;
que[rear] = x; //inserting value at rear
}
else
{
rear++;
que[rear] = x;
}
}
public int deletefront()
{
if(front == -1 && rear == -1)
{
System.out.println("Queue Underflow"); //queue is empty
return -999;
}
else if(front==rear)
{
int val = que[front]; //deleting value from front
front--;
rear--;
return val; //return the deleted value
}
else
{
int temp = que[front];
front++;
return temp;
} }
public void display()
{
86
if(front==-1 && rear == -1) //empty queue
System.out.println("Queue is Empty");
else
{
System.out.print("\nQueue is: "); //priniting the queue
for(int i=front; i<=rear; i++)
{
System.out.print(que[i] + " ");
} System.out.println();
} }
public static void main()
{
Scanner sc = new Scanner(System.in);
int c,n,d;
Queue obj = new Queue();
do
{
System.out.println("PRESS 1 TO ADD VALUE | PRESS 2 TO DELETE
VALUE\nPRESS 3 TO DISPLAY | PRESS 4 TO EXIT");
System.out.println("Enter your choice");
c= sc.nextInt(); //taking user‟s choice in which function to implement
switch(c)
{
case 1:
System.out.println("Enter number to add");
n = sc.nextInt();
obj.addrear(n);
break;
case 2:
d = obj.deletefront();
if(d!=-9999)
System.out.println("Deleted value is "+d);
break;
case 3:
obj.display();
break;
case 4:
System.exit(0);
default:
System.out.println("Invalid Choice");
} }
while(c!=4); }
}

87
VARIABLE DESCRIPTION TABLE
Variable DataType Description
size int The size of the queue.
front int The index of the first element in the queue.
rear int The index of the last element in the queue.
que[] int[] The queue array.
c int The user's choice of operation.
n int The number to be added to the queue.
d int The number deleted from the queue.

OUTPUT
PRESS 1 TO ADD VALUE | PRESS 2 TO DELETE VALUE
PRESS 3 TO DISPLAY | PRESS 4 TO EXIT

Enter your choice


1
Enter number to add
34
PRESS 1 TO ADD VALUE | PRESS 2 TO DELETE VALUE
PRESS 3 TO DISPLAY | PRESS 4 TO EXIT
Enter your choice
1
Enter number to add
233
PRESS 1 TO ADD VALUE | PRESS 2 TO DELETE VALUE
PRESS 3 TO DISPLAY | PRESS 4 TO EXIT
Enter your choice
1
Enter number to add
45
PRESS 1 TO ADD VALUE | PRESS 2 TO DELETE VALUE
PRESS 3 TO DISPLAY | PRESS 4 TO EXIT
Enter your choice
2
Deleted value is 34
PRESS 1 TO ADD VALUE | PRESS 2 TO DELETE VALUE
PRESS 3 TO DISPLAY | PRESS 4 TO EXIT
Enter your choice
3
Queue is: 233 45
PRESS 1 TO ADD VALUE | PRESS 2 TO DELETE VALUE
PRESS 3 TO DISPLAY | PRESS 4 TO EXIT
Enter your choice
4

88

You might also like