Program List

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

PROJECT PROGRAMS

 NUMBER PROGRAM (Any 15 Programs)


1. Design a class in Java to input a number and check whether it is a Fascinating Number or not. Fascinating
Numbers: Some numbers of 3 digits or more exhibit a very interesting property. The property is such that,
when the number is multiplied by 2 and 3, and both these products are concatenated with the original
number, all digits from 1 to 9 are present exactly once, regardless of the number of zeroes. Let's understand
the concept of Fascinating Number through the following example:
Consider the number 192
192 x 1 = 192
192 x 2 = 384
192 x 3 = 576
Concatenating the results: 192 384 576
It could be observed that '192384576' consists of all digits from 1 to 9 exactly once. Hence, it could be
concluded that 192 is a Fascinating Number. Some examples of fascinating Numbers are: 192, 219, 273, 327,
1902, 1920, 2019 etc.

2. A number is said to Bouncy number if the digits of the number are unsorted.
For example,
22344 - It is not a Bouncy number because the digits are sorted in ascending order.
774410 - It is not a Bouncy number because the digits are sorted in descending order.
155349 - It is a Bouncy number because the digits are unsorted.
A number below 100 can never be a Bouncy number.
Design a class in java to accept a number. Check and display whether it is a Bouncy number or not.

3. A triangular number is formed by the addition of consecutive integers starting with 1. For example,
1+2=3
1+2+3=6
1 + 2 + 3 + 4 = 10
1 + 2 + 3 + 4 + 5 = 15
Thus, 3, 6, 10, 15, are triangular numbers.
Design a class in Java to display all the triangular numbers from 3 to n, taking the value of n as an input.

4. 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:
Factors of 10 are: 1, 2, 5, 10
Magic number: A Magic number is a number in which the eventual sum of the digit 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. 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:
Sample Input:
m=10 n=100
Output: The composite magic numbers are 10,28,46,55,64,82,91,100
Frequency of composite magic numbers: 8
Sample Input:
m=120 n=90
Output: Invalid input

5. Design a class in Java to input the first 14 digits of an IMEI number and find the check (last) digit of it.
The IMEI (15 decimal digits: 14 digits plus a check digit) includes information on the origin, model, and
serial number of the device.
The check digit (x) is obtained by computing the sum of digits then computing 9 times that value modulo 10.
In algorithm form:
i. Compute the sum of the digits (52 in this case).
ii. Multiply the sum by 9 (9*52 = 468).
iii. Divide the result by 10 and note down the remainder (468 % 10)
iv. The last digit, 8, is the check digit.

6. Design a class in java to accept a number and check whether it is a valid IMEI number or not.
The IMEI is validated in three steps:
1. Starting from the right, double every other digit (e.g., 7 becomes 14).
2. Sum the digits (e.g., 14 → 1 + 4).
3. Check if the sum is divisible by 10.
For Example:
If input is IMEI = 490154203237518

Since, 60 is divisible by 10, hence the given IMEI number is Valid.

7. Lucky numbers are a sequence of natural numbers that remain after removing second, third, fourth, fifth and
so on numbers respectively from a sequence of consecutive natural numbers.
Consider the sequence of first 20 natural numbers :
Removing every second number produces the sequence 1, 3, 5, 7, 9, 11, 13, 15, 17, 19
Next removing every third number produces the sequence 1, 3, 7, 9, 13, 15, 19
Next removing every fourth number produces the sequence : 1, 3, 7, 13, 15, 19
Further deleting every fifth number we get the sequence : 1, 3, 7, 13, 19
Deletion of every sixth number is not possible and the five numbers that are lucky to escape deletion remain
indefinitely.
Design a class to enter any positive natural number ‘N’ where (1<=N<=50) and generate lucky numbers less
than the given natural number.
Test your program with the following set of data
Example 1
INPUT: N=10
OUTPUT: LUCKY NUMBERS LESS THAN 10 ARE : 1, 3 , 7
Example 2
INPUT: N=25
OUTPUT: LUCKY NUMBERS LESS THAN 25 ARE : 1, 3 , 7, 13, 19
Example 3
INPUT: N=100
OUTPUT: NUMBER NOT IN RANGE. INVALID ENTRY

8. Design a class in java to accept a number and check whether it is a keith number or not.
A Keith Number is an integer N with ‘d’ digits with the following property:
If a Fibonacci-like sequence (in which each term in the sequence is the sum of the ‘d’ previous terms) is
formed, with the first ‘d’ terms being the decimal digits of the number N, then N itself occurs as a term in the
sequence.
For example, 197 is a Keith number since it generates the sequence
1, 9, 7, 17, 33, 57, 107, 197, ………..
Some keith numbers are: 14, 19, 28, 47, 61, 75, 197, 742, 1104, 1537……………
9. A positive natural number, (for e.g. 27) can be represented as follows:
2+3+4+5+6+7
8 + 9 + 10
13 + 14
where every row represents a combination of consecutive natural numbers, which add up to 27.
Design a class, which inputs a positive natural number N and prints the possible consecutive number
combinations, which when added give, N.
Test your program for the following data and some random data.
Example 1
INPUT: N=9
OUTPUT: 4+5
2 +3+4
Example 2
INPUT: N=15
OUTPUT: 7+8
1+2+3+4+5
4+5+6

10. Design a class in java to accept a number from the user & check whether it’s a mersenne number or not.
Mersenne number are the ones which are one less than a power of 2 i.e, 1 = (12 – 1), 3 = ( 22– 1)
Sample input:
Enter a number: 8
Sample output:
8 is a mersenne number

11. Design a class in Java to input a number and check whether it is an Evil Number or not.
Evil Number : An Evil number is a positive whole number which has even number of 1’s in its binary
equivalent.
Example: Binary equivalent of 9 is 1001, which contains even number of 1’s.
A few evil numbers are 3, 5, 6, 9….
Sample input:
Enter a number: 12
Sample output:
Binary equivalent of 12 is 1100
12 is an evil number

12. Design a class to input a positive natural number N and output M(N).
The MOBIUS function M(N) for a natural number N is defined as follows:
M(N) = 1 if N = 1 [Condition 1]
M(N) = 0 if any prime factor of N is contained in N more than once [Condition 2]
M(N) = (-1)p if N is a product of ‘p’ distinct prime factors [Condition 3]
Example :
M(78) = -1 ( for 78 = 2 * 3 * 13 M(78) = ( -1)3 = -1 )
M(34) = 1 ( for 34 = 2 * 17 M(34) = ( -1)2 = 1 )
M(12) = 0 ( for 12 = 2 * 2 * 3 M(12) = 0 for 2 appears two times)
M(17) = -1 ( for 17 = 17 M(17) = ( -1)1 = -1 )

13. Design a class in java to accept a number and check whether it is a kaprekar number or not.
A positive whole number ‘n’ that has ‘d’ number of digits is squared and split into two 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 two pieces is equal to the number, then ‘n’ is a Kaprekar number. The first few Kaprekar
numbers are: 9, 45, 297 ……..
Example 1: 9
92 = 81, right-hand piece of 81 = 1 and left hand piece of 81 = 8
Sum = 1 + 8 = 9, i.e. equal to the number. Hence, 9 is a Kaprekar number.
Example 2: 45
452 = 2025, right-hand piece of 2025 = 25 and left hand piece of 2025 = 20
Sum = 25 + 20 = 45, i.e. equal to the number. Hence, 45 is a Kaprekar number.
Example 3: 297
2972 = 88209, right-hand piece of 88209 = 209 and left hand piece of 88209 = 88
Sum = 209 + 88 = 297, i.e. equal to the number. Hence, 297 is a Kaprekar number.

14. Design a class in java to enter any number from 2 to 5 and print all the combinations of digits starting from
1 to that number. Display the total number of combinations formed for the given input.
Sample input: 3
Output:
123
132
213
231
312
321
Total number of combinations: 6

15. Design a class in Java to input a number and check whether it is a Pronic Number or not.
PronicNumber : A pronic number is a number which is the product of two consecutive integers, that is, n (n
+ 1).
The first few pronic numbers are:
0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462 … etc.
Sample input:
Enter a number: 12
Sample output:
12 is a pronic number

16. A Vampire number is a composite natural number with an even number of digits that can be factored into
two natural numbers each with half as many digits as the original number and not both with trailing zeros,
where the two factors contain precisely all the digits of the original number, in any order of counting
multiplicity.
Example: 1260 = 21 x 60 ( where, 21 and 60 contain precisely all the digits of the number ) Thus, 1260 is a
Vampire number.
Accept two positive integers m and n, where m is less than n and the values of both ‘m’ and ‘n’ must be
greater than or equal to 1000 and less than or equal to 9999 as user input. Display all Vampire numbers that
are in the range between m and n (both inclusive) and output them along with the frequency, in the format
specified below:
Test your program for the following data and some random data.
Example 1
INPUT: m = 1002 n = 1640
OUTPUT: THE VAMPIRE NUMBERS ARE:
1260 1395 1435 1530
FREQUENCY OF VAMPIRE NUMBER IS: 4

17. 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 I and itself.
Example:
131
311
113
Hence, 131 is a circular prime.

18. A Goldbach number is a positive even integer that can be expressed as the sum of two odd primes.
Note: All even integer numbers greater than 4 are Goldbach numbers.
Example:
6=3+3
10 = 3 + 7
10 = 5 + 5
Hence, 6 has one odd prime pair 3 and 3. Similarly, 10 has two odd prime pairs, i.e. 3 and 7, 5 and 5.
Design a class to accept an even integer 'N' where N > 9 and N < 50. Find all the odd prime pairs whose sum
is equal to the number 'N'.
Test your program with the following data and some random data:
Example 1
INPUT:
N = 14
OUTPUT:
PRIME PAIRS ARE:
3, 11
7, 7
Example 2
INPUT:
N = 30
OUTPUT:
PRIME PAIRS ARE:
7, 23
11, 19
13, 17
Example 3
INPUT:
N = 17
OUTPUT:
INVALID INPUT. NUMBER IS ODD.
Example 4
INPUT:
N = 126
OUTPUT:
INVALID INPUT. NUMBER OUT OF RANGE.

19. Design a class in java to enter a number containing three digits or more. Arrange the digits of the entered
number in ascending order and display the result.
Sample input:
Enter a number: 4875
Sample output:
Arranged digit is 4578

20. A positive integer n is called a sphenic number if the product of three distinct factors of the given number (n)
is equal to the given number(n) and all the distinct factors are prime. In other words, if n is a sphenic integer
then n=p x q x r (p, q, and are three distinct prime numbers and their product are n).
For example: 42
Factors of 42 = 1, 2, 3, 7, 21
Factors which are prime: 2, 3, 7
Product of prime factors: 2 x 3 x 7 = 42
42 is a sphenic number.
Some other sphenic numbers are 78, 102, 105, 110, 285, 286, 290, 310, 318, 322, 345, etc.
Design a class in java to accept a number a check whether it is a sphenic number or not.

21. Design a class to generate first n Catalan numbers using formula:


(2𝑛)!
(𝑛!)2 (𝑛 + 1)
Catalan numbers are the numbers having the form of the above given formula where (n > 0). First few such
numbers are 1, 2, 5, 14, 42,....

22. Hamming numbers are positive integer numbers whose prime factors include 2,3 and 5 only.
Example:
n=6 is an hamming number as 6=2x3 .So its prime factors are limited to 2 ,3
n=8 is an hamming number as 8=2x2x2 and it has only 2 as its prime factors
n=90 is an hamming number as 90=2x3x3x5 which has only 2,3,5 as prime factors
n=14 is not a hamming number as 14=2x7 .It has 7 as one of its prime factor
n=44 is not a hamming number as 44=2x2x11. It has 11 as one of its prime factors
Design a program to accept any positive integer number and check if it is a Hamming number or not. Display
the result with an appropriate message in the format specified below. The program should also generate error
message if a negative number is entered.
Test your program for the following data and some random data.
Example 1
INPUT: Enter any number: 3600
OUTPUT: 3600= 2 x 2 x 2 x 2 x 3 x 3 x 5 x 5
3600 IS A HAMMING NUMBER
Example 2
INPUT: Enter any number: 5832
OUTPUT: 5832= 2 x 2 x 2 x 3 x 3 x 3 x 3 x 3 x 3
5832 IS A HAMMING NUMBER
Example 3
INPUT: Enter any number: 7854
OUTPUT: 7854= 2 x 3 x 7 x 11 x 17
7854 IS NOT A HAMMING NUMBER
Example 4
INPUT: Enter a number: -120
OUTPUT: NEGATIVE NUMBER ENTERED. INVALID INPUT

23. Design a class in Java to check if the given number is strontio number. Strontio numbers are those four digits
numbers when multiplied by 2 give the same digit at the hundreds and tens place.
1386*2=2772, we observe that at tens and hundreds place digits are the same. Hence, 1386 is a strontio
number. 1221*2=2442, digits at tens and hundreds place are the same. Hence, 1221 is a strontio number.
Some other strontio numbers are 1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999, 1001, 2002, 3003,
etc.

 RECURSION PROGRAM (Any 8 Programs)

24. An Evil number is a positive whole number which has even number of 1's in its binary equivalent. Example:
Binary equivalent of 9 is 1001, which contains even number of 1's. A few evil numbers are 3, 5, 6, 9….
Design a program to accept a positive whole number and find the binary equivalent of the number and count
the number of 1's in it and display whether it is a Evil number or not with an appropriate message. Output the
result in format given below:
Example 1
Input: 15
Binary Equivalent: 1111
No. of 1's: 4
Output: Evil Number
Example 2
Input: 26
Binary Equivalent: 11010
No. of 1's: 3
Output: Not an Evil Number

25. A unique-digit integer is a positive integer (without leading zeros) with no duplicates digits. For example 7,
135, 214 are all unique-digit integers whereas 33, 3121, 300 are not. Given two positive integers m and n,
where m < n, Design a class to determine how many unique-digit integers are there in the range between m
and n (both inclusive) and output them. The input contains two positive integers m and n. Assume m < 30000
and n < 30000. You are to output the number of unique-digit integers in the specified range along with their
values in the format specified below:
Sample Input:
m = 100
n = 120
Sample Output:
The Unique-Digit integers are:
102, 103, 104, 105, 106, 107, 108, 109, 120.
Frequency of unique-digit integers is : 9
Sample Input:
m = 2500
n = 2550
Sample Output:
The Unique-Digit integers are:
2501, 2503, 2504, 2506, 2507, 2508, 2509, 2510, 2513, 2514, 2516, 2517, 2518, 2517, 2530, 2519, 2530,
2531, 2534, 2536, 2537, 2538, 2539, 2540, 2541, 2543, 2546, 2547, 2548, 2549.
Frequency of unique-digit integers is: 28.

26. Design a class in java to accept a decimal number and convert it into its binary equivalent.
Sample input:
Enter a decimal number: 12
Sample output:
Binary equivalent is 1100

27. Design a class in java to accept a decimal number and convert it into its octal equivalent.
Sample input:
Enter a decimal number: 12
Sample output:
Octal equivalent is 14

28. Design a class in java to accept a decimal number and convert it into its hexadecimal equivalent.
Sample input:
Enter a decimal number: 764
Sample output:
Hexadecimal equivalent is 2FC

29. Design a class in java to accept a number and check whether it is a smith number or not.
A smith number is a composite number, the sum of whose digits is the sum of the digits of its prime factors
obtained as a result of prime factorization (excluding 1)
Sample input:
Enter a number: 666
Sample output:
666 is a smith number

30. Design a class in java to accept a number from the user & check whether it’s a emirp number or not.
A number is said to be emirp if the number itself and its reverse are prime.
Sample input:
Enter a number: 31
Sample output:
31 is an emirp number.

31. Design a class in java to accept a number and check whether it is a happy number or not.
A number is said to be a Happy number if the sum of the square of the digits are calculated till a single digit
is obtained by recursively adding the sum of the square of the digits. If the single digit comes to be 1 then the
number is a Happy number.
Example:
28 = (2)2 + (8)2 = 4 + 64 = 68
68 = (6)2 + (8)2 = 36 + 64 = 100
100 = (1)2 + (0)2 + (0)2 = 1 + 0 + 0 = 1
Sample input:
Enter a number: 28
Sample output:
28 is a happy number

32. Design a class in java to accept a range and display all Narcissistic number till the range.
A narcissistic number is a number that is the sum of its own digits each raised to the power of
the number of digits.
(1634 = 14 + 64 + 34 + 44)
Sample input:
Enter a range: 1000
Sample output:
The Narcissistic numbers are:
1 153 370 371 407

33. Design a class in Java to check if the given number is xylem or phloem. A number N will be a xylem
number if the sum of its extreme (first and last) digits is equal to the sum of mean (all digits except first and
last) digits. If the sum of extreme digits is not equal to the sum of mean digits, the number is called phloem
number.
A number N will be a xylem number if the sum of its extreme (first and last) digits is equal to the sum of
mean (all digits except first and last) digits. If the sum of extreme digits is not equal to the sum of mean
digits, the number is called phloem number.

34. Design a class in java to print ‘n’ terms of automorphic number. ( n is taken from the user)
An automorphic number is a number which is present in the last digit(s) of its square.
Sample input:
Enter no. of terms: 6
Sample output:
Automorphic numbers are:
1 5 6 25 76 376

 DATE PROGRAM (Any 7 programs)

35. Design a class in java to accept a date in dd/mm/yyyy format. Check for the validity of the date and display
an appropriate message. Year lying between 1900 - 3000 (both inclusive) will be valid.
Sample input: 17/07/2024
Sample output: Valid date
Sample input: 29/02/2022
Sample output: Not a valid date

36. Design a class in java to input a date and check whether it is a palindromic date.
Sample input:
Enter a date: 10/02/2001
Sample output:
The date is a palindromic date

37. Design a class in java to accept a day number (between 1 to 366), year (4 digits) to generate and display the
corresponding date. The program further accepts ‘n’ (1<=n<=100) from the user to compute and display the
future date corresponding to ‘n’ days after the generated date.
Sample input:
Day number: 233
Year: 2008
Days after (n): 17
Sample output:
20 August 2008
Days after 17 days: 6 September 2008

38. Design a class in java to input long integer data not less than five digit. Your program should reject it if data
is less than five digit. In the input, last four digit will be taken as year (validity of the year should be checked)
and remaining digit as total number of days. Your program should display the output as actual date.
Sample input: 272008
Sample output: 27 January 2008
Sample input: 362017
Sample output: 5 February 2017

39. Design a class in java to accept date and weekdays name of the 1st day of that month. Display the weekday of
that date.
Sample input:
Enter a date: 27/04/2017
Enter the 1st day of that month: Saturday
Sample output:
Day of the date is Thursday

40. Design a class in java to accept year, month, and the weekday’s name of the 1st day of that month. Generate
its calendar in calendar format week starting with Monday.
Sample input:
Enter a year: 2017
Enter a month: June
Enter 1st day of the month: Thursday
Sample output:
June 2017
M T W TH F S S
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30

41. Design a program which accepts a date of birth in dd/mm/yyyy format. Check whether the date is a valid date
or not. Also display the birth number i.e., 1,2,3,4,5,6,7,8,9,11
Sample Input:
Enter a date: 25/03/2005
Sample Output:
25/03/2005 is a valid date.
The birth number is 8 ( 2+5+0+3+2+0+0+5 = 17, 1+7=8)

42. Design a class to accept 2 dates in the string format dd/mm/yyyy and find the difference in days between the
2 dates.
Sample Input:
Enter Date 1: 20/12/2012
Enter Date 2: 11/02/2013
Sample Output:
Difference = 54 days

 ARRAY PROGRAM (Any 10 programs)


43. Design a class to create a 3 x 3 square matrix and accept the elements. Display the lower triangular matrix.
Lower triangular matrix is a square matrix in which all the elements above the principle diagonal will be
zero. To find the lower triangular matrix, a matrix needs to be a square matrix that is, the number of rows and
columns in the matrix need to be equal.
44. Design a class to create a 3 x 3 square matrix and accept the elements. Display the upper triangular matrix.
Upper triangular matrix is a square matrix in which all the elements below the principle diagonal are zero. To
find the upper triangular matrix, a matrix needs to be a square matrix that is, the number of rows and columns
in the matrix need to be equal.

45. Design a class to create a 3 x 3 square matrix and accept the elements. Find the product of two matrices and
print the resulting matrix.
The product of two matrices can be computed by multiplying elements of the first row of the first matrix with
the first column of the second matrix then, add all the product of elements. Continue this process until each
row of the first matrix is multiplied with each column of the second matrix.

46. Design a class to create a 3 x 3 square matrix and accept the elements. Find the transpose of the given matrix
and print the resulting matrix.

47. Design a class in java to declare a 2D array of size M x N. Sort the elements of each row in ascending order.
Display the new matrix.
Sample input:
Enter size of M: 3
Enter size of N: 3
10 2 45
5 30 15
6 1 4

Sample output:
ORIGINAL MATRIX
10 2 45
5 30 15
6 1 4

MATRIX AFTER SORTING


2 10 45
5 15 30
1 4 6

48. Design a class to declare a square matrix A[ ][ ] of order MxM where ‘M’ is the number of rows and the
number of columns, such that M must be greater than 2 and less than 10. Accept the value of M as user input.
Display an appropriate message for an invalid input. Allow the user to input integers into this matrix. Perform
the following tasks:
(a) Display the original matrix.
(b) Rotate the matrix 90° clockwise as shown below:
(c) Find the sum of the elements of the four corners of the matrix.
Sample input:
M=3
3 4 9
2 5 8
1 6 7

Sample output:
ORIGINAL MATRIX
3 4 9
2 5 8
1 6 7
MATRIX AFTER ROTATION
1 2 3
6 5 4
7 8 9
Sum of the corner elements = 20

49. Design a class 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:
(a) Sort the boundary elements in descending order using any standard sorting technique and rearrange them
in the matrix.
(b) Calculate the sum of the boundary elements.
(c) Display the original matrix, rearranged matrix and sum of the boundary elements.
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 12 8
REARRANGED MATRIX
23 15 12 11
1 13 8 9
2 6 3 8
4 5 7 8

The sum of boundary elements is = 105

50. Design a class 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:
(a) Sort the non-boundary elements in ascending order using any standard sorting technique and rearrange
them in the matrix.
(b) Calculate the sum of both the diagonals.
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
SUM OF THE DIAGONAL ELEMENTS = 59

51. Design a class 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 10. Accept the value of M as user input.
Display an appropriate message for an invalid input. Allow the user to input integers into this matrix. Perform
the following tasks:
(a) Display the original matrix.
(b) Check if the given matrix is Symmetric or not.
A square matrix is said to be Symmetric, if the element of the i th row and jth column is equal to the
element of the jth row and ith column.
(c) Find the sum of the elements of left diagonal and the sum of the elements of right diagonal of the
matrix and display them.
Test your program with the sample data and some random data:
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

52. A square matrix is said to be a Magic Square, if the sum of each row, each column and each diagonal is same.
Design a class to enter an integer number ‘n’. Create a magic square of size ‘n*n’. Finally, print the elements
of the matrix as Magic Square.
Note: n <= 5
Sample Input: Enter the size of the matrix : 4
Sample Output: The Magic Matrix of size 4×4 is:

53. A wondrous square is an n by n grid which fulfils the following conditions:


(i) It contains integers from 1 to n 2, where each integer appears only once.
(ii) The sum of integers in any row or column must add up to 0.5 * n * (n 2 + 1).
For example the following grid is a wondrous square where the sum of each row or column is 65 when n = 5
:
17 24 2 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
Design a class to read n (2 < = n < = 10) and the values stored in these n by n cells and output if the grid
represents a wondrous square or not.

54. Design a class to declare a square matrix A [ ][ ] of order ‘n’. Allow the user to input positive integers into
this matrix. Perform the following tasks on the matrix:
(i) Output the original matrix.
(ii) Find the SADDLE POINT for the matrix. If the matrix has no saddle point, output the message “NO
SADDLE POINT”.

A saddle point is an element of the matrix such that it is the minimum element for the row to which it
belongs and the maximum element for the column to which it belongs. Saddle point for a given matrix is
always unique.
Example: In the Matrix
456
789
213
Saddle point = 7 because it is the minimum element of row 2 and maximum element of column 1

55. Design a class in Java to input a 2-D array of size ‘m*n’ and print its boundary (border) elements.
For example:
56. Design a class 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. Display the matrix in such a way that the
resultant matrix appears to be the mirror image of the original matrix.
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 12 8

REARRANGED MATRIX
5 1 2 9
4 8 13 8
11 3 6 15
8 12 12 7

57. Design a class in Java to fill a square matrix of size ‘n*n” in a spiral fashion (from the inside in anti
clockwise) with natural numbers from 1 to n*n, taking ‘n’ as input.
For example: if n = 5, then n*n = 25, hence the array will be filled as given below.

58. Design a class in Java to fill a square matrix of size ‘n*n” in a circular fashion (anti clockwise) with natural
numbers from 1 to n*n, taking ‘n’ as input.
For example: if n = 4, then n*n = 16, hence the array will be filled as given below.

1 12 11 10

2 13 16 9
3 14 15 8
4 5 6 7

59. Design a class in Java to fill a square matrix of size ‘n*n” in a circular fashion (clockwise) with natural
numbers from 1 to n*n, taking ‘n’ as input.
For example: if n = 4, then n*n = 16, hence the array will be filled as given below.
60. Given a square matrix M [ ] [ ] of order ‘n’. The maximum value possible for ‘n’ is 10. Accept three different
characters from the keyboard and fill the array according to the instruction given below.
Fill the upper and lower elements formed by the intersection of the diagonals by character 1.
Fill the left and right elements formed by the intersection of the diagonals by character 2.
Fill both the diagonals by character 3.
Output the result in format given below:
Example 1
ENTER SIZE : 4
INPUT : FIRST CHARACTER : ‘*’
SECOND CHARACTER : ‘?’
THIRD CHARACTER : ‘#’
OUTPUT :
#**#
?##?
?##?
#**#
Example 2
ENTER SIZE : 5
INPUT : FIRST CHARACTER : ‘$’
SECOND CHARACTER : ‘!’
THIRD CHARACTER : ‘@’
OUTPUT :
@$$$@
!@$@!
!!@!!
!@$@!
@$$$@

61. Design a class in java to enter natural numbers in a 2D array. Shift the elements of 4 th column into the 1st
column. Elements of 1st column into the 2nd column & so on.
Sample input:
Enter a size: 4
4 7 3 2
6 1 8 3
2 3 5 1
3 9 5 7

Sample output:
Original matrix
4 7 3 2
6 1 8 3
2 3 5 1
3 9 5 7

Arranged matrix
2 4 7 3
3 6 1 8
1 2 3 5
7 3 9 5
 STRING PROGRAM (Any 10 Programs)
62. Design a class in java to accept a number of sentence in a string array. Change the sentence of odd rows
with an encryption of two characters ahead of the original characters. Also change the sentence of the even
rows by storing the sentence in reverse order.
Sample input:
Enter no. of sentence: Good morning.
Have a nice day!
It will rain today.
Sample output:
Encoded text: Jrrg pruqlqj
day nice a Have
Lw zloo udlq wrgdb

63. Design a class in java to accept a string and display the new string after encoding.
Sample input:
Enter a sentence: Good morning.
Enter the shift value: 3
Sample output:
Encoded text: Jrrg pruqlqj

64. Design a class in java to accept an encoded string and display the decoded string.
Sample input:
Kdyh d qlfh gdb!
Shift value: 3
Sample output:
Have a nice day!

65. Design a class that reads a sentence (the characters of the sentence may be capital or small or mixed) and
two positive integers and output the same sentence after replacing those words present at those given
integer places by the next character in a circular fashion according to the English Alphabets.
Input Sentence: He has good Books.
Input Integers: 2, 4
Output Sentence: He ibt good Cpplt.
(i.e. word number 2 and 4 have been replaced by the next characters in a circular fashion)
Input Sentence: Time and tide waits for none.
Input Integers: 3, 3
Output Sentence: Time and ujef waits for none.

66. A simple encryption system uses a shifting process to hide a message. The value of the shift can be in the
range 1 to 26. For example a shift of 7 means that A = U, B =V,C = W, etc.i e.
Text : A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Code: U V W X Y Z A B C D E F G H I J K L M N O P Q R S T
Fist an extra space is added to the end of the string. To make things little more difficult, spaces
within the original text are replaced with QQ before the text is encrypted. Double Q (QQ) was
selected because no English word ends in Q or contains QQ.
Additionally the coded message is printed in blocks of six characters separated by spaces. The last
block might not contain six characters. Design a class that takes the coded text (less than 100
characters), the shift value and prints the decoded original text. Your program must reject any non-
valid value for shift and display an error message “INVALID SHIFT VALUE)”. Assume all
characters are upper case.
INPUT:
CODED TEXT : “RUIJGG EVGGBK SAGG”
SHIFT : 11
OUTPUT:
DECODED TEST : BEST OF LUCK
67. Caesar Cipher is an encryption technique which is implemented as ROT13 (‘rotate by 13 places’). It is a
simple letter substitution cipher that replaces a letter with the letter 13 places after it in the alphabets, with
the other characters remaining unchanged.

Design a class to accept a plain text of length L, where L must be greater than 3 and less than 100.
Encrypt the text if valid as per the Caesar Cipher.
Test your program with the sample data and some random data:
Example 1
INPUT : Hello! How are you?
OUTPUT : The cipher text is:
Uryyb! Ubjnerlbh?
Example 2
INPUT : You
OUTPUT : INVALID LENGTH

68. Design a class in java 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.
Example: FLOW and WOLF are anagram words.

69. Design a class 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.
(a) Find the number of words beginning and ending with a vowel.
(b) 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

70. Design a class in java to accept number of sentence and the sentence & display the number of words and
the words in ascending order of their frequency.
Sample input:
Enter number of sentence: 1
Enter sentences: TO BE OR NOT TO BE
Sample output:
Total number of words: 6
Word Frequency
OR 1
NOT 1
TO 2
BE 2

71. Design a class in java to accept a sentence & display the number of times each word occurs in the entire
text
Sample input:
Enter sentences: TO BE OR NOT TO BE
Sample output:
Word Frequency
TO 2
BE 2
OR 1
NOT 1

72. Design a class in java to accept a sentence. Arrange the words contained in the sentence according to the
length of the words in ascending order.
Sample input:
Enter a sentence: Computer science by Sumita arora
Sample output:
Words Length of the words
By 2
Arora 5
Sumita 6
Science 7
Computer 8

73. Design a class in java to accept sentence and display only the unique words in the sentences and count
them.
Sample input:
Enter a sentence: Computer science by Sumita arora
Sample output:
Unique words in the sentence are:
Computer
by
Sumita

74. Design a class in java to accept a sentence and arrange the sentence in ascending order according the
potential of each word.
A=1
B=2
C=3
.
.
.
Z = 26
The potential of a word is found by adding the encrypted value of the alphabets.
Example: KITE
Potential = 11 + 9 + 20 + 5 = 45
Example:
Input: LOOK BEFORE YOU LEAP
POTENTIAL:
LOOK – 53
BEFORE – 51
YOU – 61
LEAP – 34
OUTPUT: LEAP BEFORE LOOK YOU

75. Design a class in java to accept a name and display its numerology number.
(note: raj= 18 +1 +10 = 29 = 11. 11 is the numerology number of raj. Numerology can be 1, 2, 3, 4, 5, 6, 7,
8, 9 and 11)
Sample input:
Enter your name: Riya
Sample output:
The numerology number of Riya is 8

76. Design a class in java to accept a string. Display the word, which occurs the maximum number of times
within the string.
Sample input:
Enter a sentence: TO BE OR NOT TO BE
Sample output:
The words which occurs the maximum number are
TO BE

77. Design a class in java to accept two strings. Display the new string by taking each character of the first
string from the left to right and of the second string from right to left. The letters should be taken
alternatively from each string.
Sample input: 1. HISTORY
2. SCIENCE
Sample output: HEICSNTEOIRCYS

78. Design a class in java to accept word and print all the probable letters combinations.
Sample input: TOP
Sample output: TOP
TPO
OPT
OTP
PTO
POT

79. Assume that there can be maximum 10 sentences in a paragraph. Design a class to arrange the sentences in
increasing order of their number of words.
Example :
INPUT : Please come and attend the party. Hello! How are you?
OUTPUT :
Hello = 1
How are you = 3
Please come and attend the party = 6

You might also like