Computer Project (1)
Computer Project (1)
ment
I would like to express my sincere gratitude
to all these individuals for mentoring and
supporting me in completing this Project.
3
18. Program 47
21
19. Program 49
22
20. Program 51
23
22. Program 53
24
23. Program 54
25(i)
24. Program 56
25(ii)
25. Program 58
27
26. Program 59
28
27. Bibliogra 61
phy
4
Program 1:
5
Output:
6
Algorithms:-
1. Input Reading:
2. Initialization:
Initialize variables:
o freq to count the number of Kaprekar numbers found.
o i to iterate through each number in the range.
o d, n, a, b, s for various calculations.
Initialize n to i and d to 0.
Use a while loop to count digits in i (n /= 10 and
increment d until n becomes 0).
7. Output Results:
7
Program 2:
8
Output:
9
Algorithms:
1. Input Reading:
2. Range Check:
3. Digit Extraction:
Arrays ones, teens, and tens are used to map digits and
combinations of digits to their word representations.
For example, ones[0] is "one", teens[0] is "eleven",
and tens[0] is "ten".
7. Output:
10
The final result is printed in uppercase
using result.toUpperCase().
Program 3:
11
12
13
14
Algorithms:
1. Input Dimensions of Matrices:
Prompt the user to enter the number of rows (row1, row2) and
columns (col1, col2) for two matrices (A and B).
3. Matrix Initialization:
Prompt the user to input values for matrix A and store them
in a[][].
Prompt the user to input values for matrix B and store them
in b[][].
5. Matrix Multiplication:
7. Output Results:
15
Print the original matrix C before transpose.
Print the transposed matrix transpose.
Program 4:
16
17
Output:
18
Algorithms:
1. Class Declaration:
2. Instance Variables:
3. Constructor:
19
Program 5:
20
Output:
21
Algorithms:
1. Class Declaration:
2. Instance Variables:
Inputs:
o w[]: Array of sentences.
o p[]: Array of integers representing the number of words in each
sentence.
Process: Implements a nested loop bubble sort to sort sentences (w[])
based on their corresponding word counts (p[]).
Output: Calls printResult(w, p) to print the sorted sentences along with
their word counts.
Inputs:
o w[]: Array of sentences.
o p[]: Array of integers representing the number of words in each
sentence.
Process: Iterates through w[] and p[] arrays and prints each sentence
followed by its word count.
Inputs:
o Uses Scanner to input a paragraph (pg).
Process:
o Splits the input paragraph into sentences
using StringTokenizer based on sentence-ending punctuation
(“.?!”).
o Counts the number of sentences (count).
o If the number of sentences (count) is greater than 10, prints “invalid
entry”.
o Otherwise, initializes arrays sent[] for sentences and p[] for word
counts:
22
Iterates through each sentence, trims leading and trailing
spaces, and counts words using countWords() method.
Calls sort(sent, p) to sort sentences based on word counts
and prints the sorted result.
Program 6:
23
Output:
Algorithms:
1. Class Declaration:
2. Instance Variables:
Inputs:
o Use Scanner to input a word (wrd).
Process:
o Append a space to the end of wrd to simplify the loop
logic.
o Initialize finalwrd to an empty string to store the
resulting word after removing repeated characters.
o Get the length of the word (len).
o Iterate through each character (ch) in the word:
Access the next character (ch2).
Compare ch with ch2.
If they are not equal, append ch to finalwrd.
o This effectively removes consecutive repeated
characters.
Output:
o Print the resulting word (finalwrd) after removing
repeated consecutive characters.
24
Program 7
25
26
27
Output:
28
Program 8
29
Output:
30
Algorithms:
1. Class Declaration:
Inputs:
o Use Scanner to input an integer (num).
Process:
o Print the given number.
o Check if the number is less than 100. If so,
print "The number is not a bouncy number" and
exit.
o Initialize two boolean variables:
increasing: Indicates if the digits of the
number are in increasing order.
decreasing: Indicates if the digits of the
number are in decreasing order.
o Use a loop to iterate through each digit of the
number:
Track the last digit (prev) and compare it
with the current digit (temp % 10).
Update increasing to false if any digit is
greater than the previous one.
Update decreasing to false if any digit is less
than the previous one.
Reduce temp by removing the last digit
(temp /= 10).
o Print "The number is a bouncy number" if
neither increasing nor decreasing is true,
indicating that the number is neither strictly
increasing nor decreasing.
o Otherwise, print "The number is not a bouncy
number".
31
Program 9:
32
33
Output:
34
Algorithms:
1. Class Declaration:
Inputs:
o Use Scanner to input a sentence (str), a word to be
deleted (wrd), and its position (pos).
Process:
o Initialize variables:
i: Loop variable.
count: To count words in the sentence.
len: Length of the input sentence.
pos: Position of the word to be deleted.
ch: Current character being processed.
last: Last character of the input sentence.
str1: String to store the modified sentence.
wrd: Word to be deleted.
wrd1: Temporary string to store current word
being read.
o Check if the last character of the input sentence (last)
is a valid punctuation ('.', '?', '!'). If not, print "INVALID
INPUT." and exit.
o Convert the entire sentence (str) to uppercase to
handle case insensitivity.
o Prompt the user for the word to be deleted (wrd) and
its position (pos).
o Initialize a loop to iterate through each character (ch)
in the sentence:
If ch is a space (' '), or punctuation ('.', '?', '!'), it
indicates the end of a word:
Compare wrd1 (current word) with wrd (word
to be deleted) and check if count equals pos.
If wrd1 matches wrd and count matches pos,
skip adding wrd1 to str1 (effectively deleting
the word).
Otherwise, concatenate wrd1 followed
by ch to str1.
Reset wrd1 and increment count.
35
If ch is not a space or punctuation,
concatenate ch to wrd1 (build the current word).
o Print the modified sentence (str1).
Program 10:
Output:
36
Algorithms:
1. Class Declaration:
Inputs:
o Use Scanner to input an integer (num), which is
the number to be checked for being a happy
number.
Process:
o Initialize variables:
num: Input number provided by the user.
sum: Variable to store the sum of the
squares of digits.
n: Temporary variable initialized to num.
o Print a prompt to enter a happy number.
o Do-While Loop:
Start a do-while loop to repeatedly calculate
the sum of squares of digits (sum):
Initialize sum to 0.
While Loop:
Iterate through each digit
of n until n becomes 0:
Calculate the last digit
of n using n % 10 and store it
in d.
Compute the square of d (d*d)
and add it to sum.
Update n by removing the last
digit (n = n / 10).
37
Set n to sum after completing the inner
while loop.
Continue this process until n is not
greater than 6.
o Result Evaluation:
Check if sum equals 1 after exiting the loop:
If true, print that num is a happy
number.
Otherwise, print that num is not a happy
number.
38
Program 11:
39
40
Output:
41
Algorithms:
1. Class Definition:
Initialize vowelsCount to 0.
Convert inputString to lowercase for case-insensitive
comparison.
Traverse through each character of lowerCaseString.
If the character is a vowel ('a', 'e', 'i', 'o', 'u'),
increment vowelsCount.
42
Initialize index to 0 for accessing characters
in lowerCaseString.
Use nested loops to fill vowelsMatrix row-major wise:
o Find the next vowel character in lowerCaseString.
o Store the vowel in vowelsMatrix[i][j].
o Break the loop once a vowel is found and stored.
43
Program 12
44
Output:
Program 15
45
46
Output:
47
Program 16
Output:
48
Program 17
Output:
49
Program 18
50
Output:
51
Program 20
52
Output:
53
Program 21
54
Output
55
Program 22
56
Output:
57
Program 23
58
Output:
59
Program 24
Output:
60
Program 25(i)
61
Output:
62
Program 25(ii)
63
Output:
64
Program 27
Output:
65
Program 28
66
Output:
67