Std XII A
Computer assignment
Submission date: 02 September 2025
Strings Program
1. Write a program in java to accept any three-letter word and print all the probable three-letter
combinations. No letter should be repeated within the output
Sample Input TOP
Sample Output: The required combinations of the word
TOP ΤΡΟ OTP PTO OPT POT
2. Write a program to accept two words and check whether they are Anagram or not. The words
that are made with the combinations of the letters present in the original word are called
Anagram
For example, a word is FLOW and the other word is WOLF which is formed with the
combination of the letters present in the original word.
3. Read a single sentence which terminates with a full stop (.). The words are to be separated with
a single blank space and are in lowercase. Arrange the words contained in the sentence
according to the length of the words in ascending order. If two words are of the same length
then the word occurring first in the input sentence should come first. For both, input and
output the sentence must begin in uppercase. Test your program for the given sample data and
also some random data:
Input. The lines are printed in reverse order.
Output. In the lines order printed reverse.
4. Write a program in Java to accept a string and display the new string after reversing the
characters of each word.
Sample Input: Understanding Computer Science
Sample output: gnidnatsrednu retupmoC ecneics
5. Write a program in Java to accept two strings. Display the new string by taking each character
of the first string from left to right and of the second string from right to left. The letters should
be taken alternatively from each string. Assume that the length of both the strings are same.
Sample Input: String 1: HISTORY
String 2: SCIENCE
Sample Output: HEICSNTEOIRCYS
6. A class ConsChange has been defined with the following details
Class name. ConsChange
Data Members/instance variables:
Word :Stores the word
Len : Stores the length of the word
Member functions/methods:
ConsChange() Default constructor
void readword() Stores word
void shiftcons() Shifts all the consonants of the word at the beginning followed by the vowels
(e.g. Spoon becomes Spnoo)
void changeword() Changes the case of all occurring consonants of the shifted word to
uppercase, for eg. Spnoo becomes SPNoo).
void show() Displays the original word, shifted word and the changed word.
Specify class ConsChange giving the details of the constructor(), void readword(), void shiftcons(),
void changeword() and void show(). Define the main() function to create an object and call the
functions accordingly to enable the task
7. A class SortAlpha has been defined to sort the words in the sentence in alphabetical order.
Example: Input: THE SKY IS BLUE
Output: BLUE IS SKY THE
Some of the members of the class are given below:
Class name : SortAlpha
Data members/instance variables:
sent To store a sentence
m Integer to store the number of words in a sentence
Methods/Member functions:
SortAlpha() : default constructor to initialise data members with legal initial values
void acceptsent() : to accept a sentence in UPPERCASE
void sort(SortAlpha P): sorts the words of the sentence of object P in alphabetical order and
stores the sorted sentence in the current object
void display() display the original sentence along with the sorted sentence by invoking the
method sort()
8. Design a class called Change to convert a decimal number into its equivalent number in base
16 and vice-versa.
For example,
The decimal number 35 is 23 in base 16.
The decimal number 107 is 6B in base 16.
Some of the members of the class Change are as follows:
Class name : Change
Data members/instance variables
a[] :An integer array.
n :Integer to be converted to base 16.
Member functions/methods
Change() Constructor to initialise 0 to instance variables.
void input() To accept an integer to be converted to base 16.
void decihexa(String str) : To convert hexadecimal number to decimal form
void hexadeci() : To convert decimal integer 'n' to hexadecimal
9. A class Capital has been defined to check whether a sentence has words beginning with a
capital letter or not.
Some of the members of the class are given below:
Class name: Capital
Data members/instance variables:
sent to store a sentence
freq : Stores the frequency of words beginning with a capital letter
Member functions/methods:
Capital() : default constructor
void input() : to accept the sentence
boolean isCap(String w): checks and returns true if, the word begins with a capital letter,
otherwise returns false
void display() displays the sentence along with the frequency of the words beginning with a
capital letter
10. A class Encode has been defined to replace only the vowels in a word by the next
corresponding vowel and form a new word.
i.e. A -> E, E -> I,I-O, O -> U,U -> A
Example: Input: Institution
Output: Onstotatoun
Some of the members of the class are given below:
Class name : Encode
Data members/instance variables:
word : to store a word
length:integer to store the length of the word
new_word: to store the encoded word
Member methods/functions:
Encode(): Default constructor to initialise data members with legal initial values
void acceptWord()To accept a word
void nextVowel()To replace only the vowels from the word stored in ‘word’ by the next
corresponding vowel and to assign it to ‘new_word’, with the remaining alphabets unchanged
void display()To display the original word along with the encrypted
Array Programs
1. Write a program in java to store the numbers in a 4 x 4 matrix in Double Dimensional Array.
Arrange the numbers of each row in ascending order and display the result.
2. Write a program to declare a square matrix A[][] of order M * M where M is an positive integer
and represents the number of rows and columns. 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
(a) Display the original matrix.
(b) Check if the given matrix is symmetric or not. If the element of the ith row and jth column is
same as element of the jth row and ith column, then the matrix is called symmetric matrix.
3. Write a program in Java to create a 4 x 4 matrix. Now, swap the elements of 0th row with 3rd row
correspondingly. Display the result after swapping
Sample Input
55 33 26 14
81 86 31 10
58 64 17 12
22 14 23 25
Sample Output
22 14 23 25
81 86 31 10
58 64 17 12
55 3 26 14
4.Write a program to declare a square matrix A[][] of order (MxM) where M must be greater than 3
and less than 10. Allow the user to input positive integers into this matrix Perform the following
tasks on the matrix:
(a) Calculate the sum of both the diagonals.
b) Display the original matrix, the diagonal elements of the matrix with their sum.
5. Declare a square matrix A[][] of order MxM where M is the number of rows and the number of
columns, Allow the integers into this matrix, perform the following tasks:
(a) Display the original matrix.
(b) Find the sum of the elements of the four corners of the matrix. Test your program for the
following data and also some random data:
Input
123
654
789
Sum of the corner elements: 20