Computer Program
Computer Program
import java.util.Scanner;
public Encrypt() {
Sen = "";
NewSen = "";
len = 0;
}
1
} else {
if (isVowel(word.charAt(0))) {
reverseWord(word);
}
NewSen += word.toString() + " ";
word.setLength(0);
}
}
// Process the last word in the sentence
if (word.length() > 0) {
if (isVowel(word.charAt(0))) {
reverseWord(word);
}
NewSen += word.toString();
}
}
2
encryptObj.display();
encryptObj.reverse();
}
}
program 2
A class DeciHexa has been defined to convert a decimal number
into its equivalent Hexadecimal number. Some of the members of
the class are given below:
Class name: DeciHexa
Data members/instance variables:
n: stores the decimal number
hexa: string to store the hexa decimal equivalent number
Member functions: DeciHexa(): constructor to initialize the data
members n = 0, hexa=†â€
void getnum(int nn): assign nn to n
void deci_hexa(): calculates the hexa decimal equivalent of ‘nâ
€™ and stores it in hexa using the recursive technique
void show(): displays the decimal number ‘n’, calls the
function deci_hexa() and displays its hexa decimal equivalent.
(a) Specify the class DeciHexa, giving details of the
constructor( ), void getnum(int), void deci_hexa( ) and void
show(). Also define a main() function to create an object and
call the functions accordingly to enable the task. ​​[8]
(b) State any two disadvantages of using recursion.
import java.util.Scanner;
public DeciHexa() {
n = 0;
hexa = "";
}
3
private void convertToHexadecimal(int decimal) {
if (decimal != 0) {
int remainder = decimal % 16;
convertToHexadecimal(decimal / 16);
if (remainder < 10) {
hexa += Integer.toString(remainder);
} else {
hexa += (char) ('A' + remainder - 10);
}
}
}
program 3
A class ArrayMin contains a square matrix which finds the
smallest element in each column.
Some of the members of the class are given below:
Class name : ArrayMin
Data members/instance variables:
arr[ ] [ ] : array to store character elements
m : to store the order of the matrix
Member functions/methods:
ArrayMin(int mm ) : parameterized constructor to initialize the
size of the matrix, m=mm and to declare the array
void readArray() : to accept the array elements
void small( ) : finds and displays the smallest element in each
column with appropriate message.
int sumofarray() : finds and returns the sum of the elements
whose ASCII codes are even.
void display( ) : to display the array in a matrix form, and also
displays the sum of the elements whose ascii code is even by
invoking sumofarray(). And also displays the array elements
equivalent ASCII codes in matrix form.
For example:
4
If array arr[][]= A B C
D E F
G H I
Its equivalent ASCII code in matrix form
65 66 67
68 69 70
71 72 73
Specify the class ArrayMin giving the details of readArray(),
small(), sumofarray(), display(). Define a main( ) function to
create an object and call all the functions accordingly to enable
the task..
import java.util.Scanner;
5
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
if ((int) arr[i][j] % 2 == 0) {
sum += (int) arr[i][j];
}
}
}
return sum;
}
6
7