ISC Computer Project 2019-20 2
ISC Computer Project 2019-20 2
Note: Your Project must have Cover Page, Certificate, Acknowledgements, Index Page, Topicwise
Questions, Algorithm, Program Listing, Output Listing
Note: Submit for assessment the softcopy on pen drive and hard copy in a file, of the
following programs to be done as part of continuous year long class work
assignments on the given submission dates as mentioned topic wise below
Important Note: Attempt the programs to the best of your ability completely on
your own in BlueJ Ensure that you do not discuss the program logic or take any help
or hint from anyone or anywhere else as this will defeat the purpose oof this project.
The purpose of this project/assignments is your logic and programming skill
development. Unless you do the program entirely on your own in BlueJ and do not
copy or discuss the algorithm or take any help orhint from others , your logic and
programming skills wont develop. Even if you are unable to crack the program and
get desired program output as on the date of topic submission , still you must
attempt the program only by yourself
Question 1
An electronics shop has announced the following seasonal discounts on the purchase of
certain items.
Write a program based on the above criteria, to input name, address, amount of purchase
and the type of purchase (L for Laptop and D for Desktop) by a customer. Compute and
print the net amount to be paid by a customer along with his name and address.
( Hint : discount = discount rate/100) * amount of purchase
Net amount = amount of purchase – discount )
Purchase Amount
in Rs.
Discount on
Laptop
Discount on
Desktop PC
0 - 25000 0.0% 5.0%
25001 – 57000 5.0% 7.5%
57000 - 100000 7.5% 10.0%
More than 100000 10.0% 15.0%
Question 2
Input : Type 1 for triangle and Input : Type 1 for triangle and
Type 3 for exapmple 3 Type 4 for exaample 4 Type 5 for examplle 5 Type 6 for example
6 Type 7 for example 7
Output:
22
333
4444
55555
Question 3
Write a program to input a sentence and print the number of characters found in the longest
word of the given sentence.
For example if S = “India is my country” then the output should be 7.
Question 4
(a) void num_calc( int num , char ch) with one integer argument and one character
(b) void num_calc( int a, int b, char ch) with two integer arguments and one character
argument. It computes the product of integer arguments if ch is ‘p’ else adds the integers.
(c) void num_calc( String s1, String s2) with two string arguments, which prints
Question 5
Write a menu driven program to accept a number from the user and check whether it is a
‘BUZZ’ number or to accept any two numbers and print the ‘GCD’ of them.
(a) A BUZZ number is the number which either ends with 7 or divisible by 7.
(b) GCD (Greatest Common Divisor) of two integers is calculated by continued division
method. Divide the larger number by the smaller; the remainder then divides the previous
divisor. The process is repeated till the remainder is zero. The divisor then results the GCD.
Question 6
Write a program to read the data, calculate and display the following:
(b) Print the roll number and average marks of the students whose average mark is
above 80.
(c) Print the roll number and average marks of the students whose average mark is
below 40.
Question 7.
Write a program to calculate and print the sum of odd numbers and the sum of even numbers
for the first n natural numbers. The integer n is to be entered by the user.
Question 8.
A cloth showroom has announced the following festival discounts on the purchase of items,
based on the total cost of the items purchased.
Write a program to input the total cost and to compute and display the amount to be paid by
the customer after availing the discount.
Question 9.
Question 10.
Write a program that outputs the results of the following evaluations based on the numbered
entered by the user.
Questions 11.
Name Marks
* *
* *
* *
Write a program to input the names and marks of the students in the subject Calculate and
display:
(ii) The highest mark in the subject and the name of the student
Write a program to accept 15 integers from the keyboard, assuming that no integer entered is
a zero. Perform selection sort on the integers and then print them in ascending order.
Question 13.
Member methods:
(i) To accept the details of a teacher including the monthly salary.
(iii) To compute the annual Income Tax as 5% of the annual salary above Rs. 1,75,000.
Write a main method to create object of a class and call the above member method.
Question 14.
Write a program to compute and display the sum of the following series:
Question 15.
Write a program to initialize the given data in an array and find the minimum and maximum
values along with the sum of the given elements.
Numbers : 2 5 4 1 3
Output: Minimum value: 1
Maximum value: 5
Sum of the elements: 15
Question 16.
Write a program to enter a sentence from the keyboard and count the number of times a
particular word occurs in it. Display the frequency of the search word.
Example:
INPUT:
Enter a sentence : the quick brown fox jumps over the lazy dog.
Enter a word to be searched : the
OUTPUT:
Searched word occurs : 2 times.
Questions 17.
Using a switch statement, write a menu driven program to convert a given temperature from
Fahrenheit to Celsius and vice versa. For an incorrect choice, an appropriate error message
should be displayed.'
Questions 18.
Write a program using a method Palin( ), to check whether a string is a Palindrome or not. A
Palindrome is a string that reads the same from left to right and vice versa.
E.g. MADAM, ARORA, ABBA, etc.
Question 19.
Member functions:
Write a program to compute the tax according to the given conditions and display the output
Output:
----
----
----
Question 20.
Write a program to input a string and print out the text with the uppercase and lowercase
letters reversed, but all other characters should remain the same as before.
Question 21.
Define a class and store the given city names in a single dimensional array. Sort these
Question 22.
Write a menu driven class to accept a number from the user and check whether it is
same as read in the right order ) Example : 11, 101, 151 etc.
(b) Perfect number - ( a number is called Perfect if it is equal to the sum of its factors
Question 23.
Write a class with the name volume using function overloading that computes the volume of
Question 24.
Write a program to calculate and print the sum of each of the following series:
2 5 8 11 20
Question 25.
Write a class with name employee and basic as its data member, to find the gross pay of an
employee for the following allowances and deduction. Use meaningful variable.
Question 26.
Write a program to input any given string to calculate the total number of characters and
vowels present in the string and also reverse the string.
Example: INPUT
OUTPUT:
Number of Vowels : 01
Question 27.
Question 28.
Write a program to bubble sort the following set of values in ascending order. 5, 3, 8, 4, 9, 2, 1,
12, 98, 16
Output:
1
12
16
98
Questions 29.
Write a program to print the sum of negative numbers, sum of positive even numbers and
sum of positive odd numbers from a list of numbers (N) entered by the user. The list
terminates when the User enters a zero.
Questions 30.
Write a program to initialize an array of 5 names and initialize another array with their
respective telephone numbers. Search for a name input by the user, in the list. If found,
display "Search Successful" and print the name along with the telephone number, otherwise
display "Search unsuccessful. Name not enlisted".
Question 31
Design a class RailwayTicket with the following description:
Instance variables/data members:
String name: to store the name of the customer.
String coach: to store the type of coach customer wants to travel.
long mobno: to store customer’s mobile number.
int amt: to store basic amount of ticket.
int totalamt: to store the amount to be paid after updating the original amount.
Methods:
void accept(): to take input for name, coach, mobile number and amount.
void update(): to update the amount as per the coach selected. Extra amount to
be added in the amount as follows:
Question 32
Write a program to input a number and check and print whether it is a Pronic
number or not. Pronic number is the number which is the product of two
consecutive integers.
Examples:
12 = 3 × 4
20 = 4 × 5
42 = 6 × 7
Question 33
Write a program in Java to accept a string in lowercase and change the first letter
of every word to uppercase. Display the new string.
Sample INPUT: we are in cyber world
Sample OUTPUT: We Are In Cyber World
Question 34
Design a class to overload a function volume() as follows:
(i) double volume(double r) – with radius ‘r’ as an argument, returns the volume
of sphere using the formula:
v = 4 / 3 × 22 / 7 × r3
(ii)double volume(double h, double r) – with height ‘h’ and radius ‘r’ as the
arguments, returns the volume of a cylinder using the formula:
v = 22 / 7 × r2 × h
(iii) double volume(double l, double b, double h) – with length ‘l’, breadth ‘b’ and
height ‘h’ as the arguments, returns the volume of a cuboid using the formula:
v=l×b×h
Question 35
Write a menu-driven program to display the pattern as per user’s choice:
Pattern 1 Pattern 2
ABCDE B
ABCD LL
ABC UUU
AB EEEE
A
For an incorrect option, an appropriate error message should be displayed.
Question 36
Write a program to accept name and total marks of N number of students in two
single subscripts array name[] and totalmarks[].
Question 37.
Define a class Electric Bill with the following specifications:
class: ElectricBill
Instance Variable/ data member:
String n – to store the name of the customer
int units – to store the number of units consumed
double bill – to store the amount to paid
Member methods:
Void accept() – to accept the name of the customer and number of units
consumed
Void calculate() – to calculate the bill as per the following tariff :
Number of units — Rate per unit
First 100 units — Rs.2.00
Next 200 units — Rs.3.00
Above 300 units — Rs.5.00
A surcharge of 2.5% charged if the number of units consumed is above 300 units.
Void print() – To print the details as follows :
Name of the customer ………
Number of units consumed ……
Bill amount …….
Write a main method to create an object of the class and call the above member
methods.
Question 38.
Write a program to accept a number and check and display whether it is a spy
number or not.
(A number is spy if the sum its digits equals the product of the digits.)
Example: consider the number 1124 , sum of the digits = 1 + 1 + 2 + 4 = 8
Product of the digits = 1 X 1 X 2 X 4=8
Question 39.
Using switch statement, write a menu driven program for the following:
i) To find and display the sum of the series given below:
S = x1 – x2 + x3 – x4 + x5 … – x20
(where x=2)
ii) To display the following series:
1 11 111 1111 11111
For an incorrect option, an appropriate error message should be displayed.
Question 40.
Write a program to input integer elements into an array of size 20 and perform
the following operations:
i) Display largest number from the array
ii) Display smallest number from the array
iii) Display sum of all the elements of the array
Question 41:
Design a class to overload a function check() as follows:
i) void check(String str, char ch) – to find and print the frequency of a character
in a string.
Example :
Input — Output
Str = “success” number of s present is=3
ch = ‘s’
ii) void check (String s1) – to display only the vowels from string s1 , after
converting it to lower case.
Example :
Input:
S1= “computer” output: o u e
Question 42:
Write a program to input forty words in an array. Arrange these words in
descending order of alphabets, using selection sort technique. Print the sorted
array.
Question 43.
Define a class named BookFair with the following description:
Member Methods:
(i) BookFair() – Default constructor to initialize data members.
(ii) void Input() – To input and store the name and the price of the book.
(iii) void calculate() – To calculate the price after discount. Discount is calculated
based on the following criteria.
PRICE DISCOUNT
Less than or equal to Rs 1000 2% of price
More than Rs 1000 and less than or equal to Rs 3000 10% of price
(iv) void display() – To display the name and price of the book after discount.
Write a main method to create an object of the class and call the above member
methods.
Question 44.
Using the switch statement, write a menu driven program for the following:
1
23
456
7 8 9 10
11 12 13 14 15
I
IC
ICS
ICSE
For an incorrect option, an appropriate error message should be displayed.
Question 45.
Special words are those words which starts and ends with the same letter.
Examples:
EXISTENCE
COMIC
WINDOW
Palindrome words are those words which read the same from left to right and
vice-versa.
Example:
MALAYALAM
MADAM
LEVEL
ROTATOR
CIVIC
All palindromes are special words, but all special words are not palindromes.
Write a program to accept a word check and print whether the word is a
palindrome or only special word.
Question 46:
Design a class to overload a function SumSeries() as follows:
(i) void SumSeries(int n, double x) – with one integer argument and one double
argument to find and display the sum of the series given below:
s = (x/1) – (x/2) + (x/3) – (x/4) + (x/5) … to n terms
(ii) void SumSeries() – To find and display the sum of the following series:
s = 1 + (1 X 2) + (1 X 2 X 3) + … + (1 X 2 X 3 X 4 X … 20)
Question 47:
Example:
Question 48:
Write a program to initialize the seven Wonders of the World along with their
locations in two different arrays. Search for a name of the country input by the
user. If found, display the name of the country along with its Wonder, otherwise
display “Sorry Not Found!”
Seven wonders – CHICHEN ITZA, CHRIST THE RDEEEMER, TAJMAHAL, GREAT
WALL OF CHINA, MACHU PICCHU, PETRA, COLOSSEUM
Locations – MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY
Example – Country Name: INDIA Output: INDIA – TAJMAHAL
Country Name: USA Output: Sorry Not Found!
Question 49.
Question 50
5 4321
5 432
5 43
5 4
5
Question 51
Write a program in to input and store all roll numbers, names and marks in 3
subjects of n number of students in five single dimensional arrays and display
the remark based on average marks as given below:
75 – 84 DISTINCTION
60 – 74 FIRST CLASS
40 – 59 PASS
Question 52
(iii) void Joystring(String s1, String s2) with two string arguments that combines
the two strings with a space between them and prints the resultant string
Example :
Input value of s1 = "COMMON WEALTH"
s2 = "GAMES"
Output : "COMMON WEALTH GAMES"
(use library functions)
Question 53
Question 54.
Define a class named movieMagic with the following description:
Instance variables/data members:
int year – to store the year of release of a movie
String title – to store the title of the movie.
float rating – to store the popularity rating of the movie.
(minimum rating = 0.0 and maximum rating = 5.0)
Member Methods:
(i) movieMagic() Default constructor to initialize numeric data members to 0 and String data
member to “”.
(ii) void accept() To input and store year, title and rating.
(iii) void display() To display the title of a movie and a message based on the rating as per the
table below.
RATING MESSAGE TO BE DISPLAYED
0.0 to 2.0 Flop
Write a main method to create an object of the class and call the above member methods.
Question 55.
A special two-digit number is such that when the sum of its digits is added to the product of its
digits, the result is equal to the original two-digit number.
Example: Consider the number 59.
Sum of digits = 5 + 9 = 14
Product of its digits = 5 x 9 = 45
Sum of the sum of digits and product of digits= 14 + 45 = 59
Write a program to accept a two-digit number. Add the sum of its digits to the product of its digits.
If the value is equal to the number input, output the message “Special 2-digit number” otherwise,
output the message “Not a Special 2-digit number”.
Question 56.
Write a program to assign a full path and file name as given below. Using library functions,
extract and output the file path, file name and file extension separately as shown.
Input C:\Users\admin\Pictures\flower.jpg
Output Path: C:\Users\admin\Pictures\
File name: flower
Extension: jpg
Question 57.
Design a class to overload a function area() as follows:
(i) double area(double a. double b, double e) with three double arguments, returns the
area of a scalene triangle using the formula:
where
(ii) double area(int a, int b, int height) with three integer arguments, returns the area of a trapezium
using the formula:
(iii) double area(double diagonal1, double diagonal2) with two double arguments, returns
the area of a rhombus using the formula:
Question 58.
Using the switch statement. write a menu driven program to calculate the maturity amount of a
Bank Deposit.
The user is given the following options:
(i) Term Deposit
(ii) Recurring Deposit
For option (i) accept principal(P), rare of ¡interest(r) and time period in years(n). Calculate and
output the maturity amount(A) receivable using the formula
For option (ii) accept Monthly Installment (P), rate of interest(r) and time period in months (n).
Calculate and output the maturity amount(A) receivable using the formula
Question 59.
Write a program to accept the year of graduation from school as an integer value from the user.
Using the Binary Search technique on the sorted array of integers given below, output the message
‘Record exists’ if the value input is located in the array. If not, output the message Record does
not exist”.
(1982, 1987, 1993. 1996, 1999, 2003, 2006, 2007, 2009, 2010)
Question 60:
Question 62:
Write a program that encodes a word into Piglatin. To translate word into Piglatin
word, convert the word into uppercase and then place the first vowel of the
original word as the start of the new word along with the remaining alphabets.
The alphabets present before the vowel being shifted towards the end followed
by “AY”.
Sample Input(1): London Sample Output(1): ONDONLAY
Sample Input(2): Olympics Sample Output(2): OLYMPICSAY
Question 63:
Question 66
Question 67
Given below is a hypothetical table showing rates of Income Tax for male
citizens below the age of 65 years:
Is greater than 1,60,000 and less than or equal to 5,00,000 ( TI – 1,60,000 ) * 10%
Is greater than 5,00,000 and less than or equal to 8,00,000 [ (TI - 5,00,000 ) *20% ] + 34,000
Write a program to input the age, gender (male or female) and Taxable Income
of a person.If the age is more than 65 years or the gender is female, display
“wrong category*.
If the age is less than or equal to 65 years and the gender is male, compute and
display the Income Tax payable as per the table given above.
Question 68
Write a program to accept a string. Convert the string to uppercase. Count and
output the number of double letter sequences that exist in the string.
Sample Input: “SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE
Sample Output: 4
Question 69
Example:
(i) Input value of n=2, ch=’O’
Output:
OO
OO
(ii) Input value of x=2, y=5
Output:
@@@@@
@@@@@
(iii) Output:
*
**
***
Question 70
Question 71
Question 72.
Question 73.
Write a program to input and sort the weight of ten people. Sort and display
them in descending order using the selection sort technique. Question 6.
Write a program to input a number and print whether the number is a special
number or not. (A number is said to be a special number, if the sum of the
factorial of the digits of the number is same as the original number).
Question 74
Example
Sample Input : computer
Sample Output : cpmpvtfr
Question 75.
Design a class to overload a function compare ( ) as follows:
(a) void compare (int, int) – to compare two integer values and print the greater
of the two integers.
(b) void compare (char, char) – to compare the numeric value of two character
with higher numeric value
(c) void compare (String, String) – to compare the length of the two strings and
print the longer of the two.
Question 76
Write a menu driven program to perform the following . (Use switch-case
statement)
(a) To print the series 0, 3, 8, 15, 24 ……. n terms (value of ‘n’ is to be an input
by the user).
(b) To find the sum of the series given below:
S = 1/2+ 3/4 + 5/6 + 7/8 … 19/20
Question 77.
Write a program to perform binary search on a list of integers given below, to search for an
element input by the user. If it is found display the element along with its position, otherwise
display the message “Search element not found”.
5,7,9,11,15,20,30,45,89,97
Question 78
Question 79
Shasha Travels Pvt. Ltd. gives the following discount to its customers:
Ticket amount Discount
Above Rs 70000 – 18%
Rs 55001 to Rs 70000 – 16%
Rs 35001 to Rs 55000 – 12%
Rs 25001 to Rs 35000 – 10%
less than Rs 25001 – 2%
Write a program to input the name and ticket amount for the customer and calculate the discount
amount and net amount to be paid. Display the output in the following format for each customer :
1 SL. NO. Name Ticket
charges Discount Net
amount
2 1 -
-
-
-
(Assume that there are 15 customers, first customer is given the serial no (SlNo.) 1, next customer
2 … and so on.
Question 80
Write a menu driven program to accept a number and check and display whether it is a Prime
Number or not OR an Automorphic Number or not. (Use switch-case statement).
(a) Prime number : A number is said to be a prime number if it is divisible only by 1 and itself and
not by any other number. Example : 3,5,7,11,13 etc.
(b) Automorphic number : An automorphic number is the number which is contained in the last
digit(s) of its square.
Example: 25 is an automorphic number as its square is 625 and 25 is present as the last two digits.
Question 81.
Write a program to store 6 element in an array P, and 4 elements in an array Q and produce a third
array R, containing all elements of array P and Q. Display the resultant array
Example:
1 INPUT OUTPUT
2 P[] Q
[] R []
3 4 19 4
4 6 23 6
5 1 7 1
6 2 8 2
7 3 3
8 10 10
9 19
10 23
11 7
12 8
Question 82
Write a program to input a string in uppercase and print the frequency of each character.
1 INPUT :
COMPUTER
HARDWARE
2 OUTPUT :
3 CHARACTERS
FREQUENCY
4 A 2
5 C 1
6 D 1
7 E 2
8 H 1
9 M 1
10 O 1
11 P 1
12 R 3
13 T 1
14 U 1
15 W 1
Question 83
ASCII values.
SampLe i/p: A
Question 85
Sampke i/p: p
p is in lower case.
* */
Question 86
Question 88
initials(i.e first alphabet of each word). display the longest word and
Sample o/p: L K A ` * */
Question 89
Question 90
display the longest word and the length of the longest word present
in the string.
checked :E
Question 91
years. ` * */
Question 92
MOHAN BAGAN"
word :8 ` * */
Question 93
in string:
Frequency of 'E' = 3
Frequency of 'I' = 3
Frequency of 'O' = 2
Frequency of 'U' = 1 * */
Question 94
/**
following
output:
Play. * */
Question 95
each character.
ASCII of L = 75
ASCII OF U = 84
ASCII OF E = 69
ASCII of L = 73 * */
Question 96
Question 97
Question 98
/**16. Write a program in java to enter a string and display all the
String.
Question 99
a reverse order.
Question 100
within a string.
e */
Question 101
YEAR */
Question 102
replace the word 'Blue' with 'red'. The new string is displayed as
*/
Question 103
Question 104
new word by replacing only the vowels with the character following
it.
Sample i/p: Computer
Question 105
/*23. Write a program to input a word & print the new word
Question 106
Question 107
NO OF VOWELS PRESENT IN
TECHNOLOGY :3 */
Question 108
/**
making it a palindrome.
ICSEESCI */
Question 109
2,U-1 * */
Question 110
APPLE.
Question 111
/**29A.
BLUEJ
BLUE
BLU
BL
*/
/**29B
E E
UUU
L L L L
B B B B B
*/
/**29C.
BLUEJ
LUEJ
UEJ
EJ
*/
Question 112
/**30A.
ABCDE
BCDE
CDE
DE
F
*/
/**30B.
BC
DEF
GHIJ
KLMNO
*/
/**30C.
ABCDE
ABCDA
ABCAB
ABABC
AABCD
*/
/*30D.
ABCDE
BCDE
CDE
DE
*/
/**30E. Write a program to display the pattern
EDCBA
EDCB
EDC
ED
*/
AB
ABC
ABCD
ABCDE
*/
Question 113
Example 1
Sample Output:
*****
****
***
**
Example 2
Sample Output:
ABCDE
ABCD
ABC
AB
A */
Question 114
displayed.
Example 1
Sample Output:
L L
U U U
E E E E
J J J J J
Example 2
Sample Output:
BLUEJ
BLUE
BLU
BL
B */
/**32A.
BLUEJ
BLUE
BLU
BL
*/
/*32B.
*B
* BL
* BLU
* BLUE
* BLUEJ
*/
/**32C.
BLUEJ
LUEJB
UEJBL
EJBLU
JBLUE
*/
/*32D.
BLUEJ
BLUE
BLU
BL
*/
/**32E.
BL
BLU
BLUE
BLUEJ
*/
/**32F.
ABCDEF
GHIJK
LMNO
PQR
ST
*/
Q 9B
A class called EvenSeries has been defined to find the smallest value of integer, n, such that,
2 + 4/2!+ 8/3!+16/4!+….2n/n! >= S, where 2.0 < S < 7.0.
Some of the members of the class EvenSeries are given below:
Class name : EvenSeries
Data members:
n : long integer type to store number of terms.
S : float variable where 2.0 < S < 7.0.
k : float variable to store the value of series evaluated.
Member functions:
EvenSeries() : constructor to initialize data members to 0.
void accept() : to accept value of data member S.
long fact(long x) : to compute and return factorial of x.
voiddisp() : calculates and displays the least value of n.
Specify the class EvenSeries giving details of the constructor and functions void accept(),
long fact(long)
and void disp(). The main function need not be written.
Q Extra)
WAP that obtain input comprising of five numbers and averages them. Use Scanner object
for input purposes.
Q2. Write a menu driven class to accept a number from the user and
using switch-case construct check whether it is a Palindrome or find
the sum of digits of the number.
Palindrome is a number which when read in reverse order is same as
read in the right order. Eg:11,101,151.[Hint: Write a function
boolean isPalindrome(int n). Invoke this function in the switch-case.]
Find the number of digits of the number, the sum of the digits, the
product of the digits, the average of the digits and the highest and
lowest digit of the number Eg. 521 has 3 digits, sum of digits = 8,
product of digits = 10, average = 2.66, smallest digit = 1
Q3.
Q3A.
Q3B.
Sum= 1 + x/1!+x3/2!+x5/3!+……..+x2n-1/n!
A class seriessum has been defined to calculate the sum of the above
series. Some of the members
of the class are given below:
Class name : seriessum
Data members
x, n : int
sum : double
Member functions
sumseries() : constructor
int factorial(int n) : calculates and returns the factorial of n( n!)
where n!=1 x 2 x 3 x 4 x….x n.
double term(int p, int q): Calculates and returns the value of p/q!
by making
use of factorial(int).
void accept() : Inputs the value of member data x,n
void displaysum() : displays the value of member data sum.
double calsum() : calculates the sum of the given series using the
appropriate
data and other member functions.
a) Specify the class sumseries giving details of the constructor, int
factorial(int), double term(int,int), void displaysum(). You may
assume that other member functions are written for you. You do not
need to write the main function.
b) What care do you need to take while designing double term(int,
int).
Q3C
Q3D
Q3E
Q3F
Q3H
WAP to input a number and check whether it is a Mersenne number or
not. A Mersenne number has all ones in its Binary counterpart, it can
also be defined as n2 – 1 for e.g. Binary of 7 = (111)2 which is also
equal to 23 – 1
Binary of 15 = (1111)2 which is also equal to 24 – 1
Q3I
Q3J
Program to print GCD and LCM of two numbers using Euclid’s method.
Methods:
public int lcm(int a, int b)
public int gcd(int a, int b)
void Relation(int a, int b)
public static void main(String [] args)
Sample Input/Output
Enter two numbers
57 24
The LCM of 57 and 24 is : 456
The GCD of 57 and 24 is : 3
The product of lcm and gcd of 57 and 24 is : 1368
The product of 57 and 24 is : 1368
It satisfies the equation: lcm(a, b) * gcd(a, b) = ab
Q3J
Sample Input/Output
Enter limit: 13
(1/3 + 1/5) + (1/5+ 1/7) + (1/11 +1/13)
Brun’s Constant below limit 13 is : 1.0440226793289185
Q3K
Create a Java class that stores original numeerator and denominator of a fraction and then
simplifies it to find numerator and denominator of simplified fraction.
Class name : RationalClass
Instance Variables :
int numerator
int denominator
int nr : numerator of simplified fraction
int dr : denominator of simplified fraction
Methods:
simplify()
gcd(int,int)
print() : prints fraction in original as weell as in simplified form
Constructor : receives two parameters and initialises the numerator and denominator
main() : reads the values for numerator and denominatorcand then prints the simplifiedd
expression.
QExtra)
Q.4 A class Student defines the personal data of a student while another class Marks defines
the register number, name of subject and marks obtained by the student. The details of both
the classes are given below:
Member functions
Member functions
a) Specify the class Student giving details of the functions void inpdetails() and void show().
b) Specify the class Marks using the concept of inheritance giving details of the functions
void inpdetails() and void show(). The main function need not be written.
Q.5. A super class Stock has been defined to store the details of the stock of a retail
store. Define a subclass Purchase to store the details of the items purchased with
the new rate and updates the stock. Some of the members of the classes are
given below:
Data members:
Member functions:
Data members
purchased item
Member functions
void update() : to update stock by adding the previous quantity by the purchased quantity
and replace the rate of item if there is a difference in the purchase rate of the item if there is
a difference in the purchase rate. Also update the current stock value as: (quantity * unit
price)
void display() : to display the stock details before and after updation
Specify the class Stock, giviersion (a version number or a date) , constructor and other
functions. Using the concept of inheritance, specify the class Purchase giving details of the
constructor(…) and other methods. The main function need not be written.
Q.6 A super classBank has been defined to store the details of a customer. Define a sub-
class Accountthat enables transactions for the customer with the bank. The details of both
the classes are given below:
Class name: Bank
Data members/instance variables:
name: stores the name of the customer
accNo: stores the account number
p: stores the principal amount in decimals
Member functions/methods:
Bank(…): parameterized constructor to assign values to the instance variables
void display(): displays the details of the customer
Class name: Account
Data members/instance variables:
amt: stores the transaction amount in decimals
Member functions/methods:
Account(…): parameterized constructor to assign values to the instance variables of both the
classes
void deposit(): accepts the amount and updates the principal as p = p + amt
void withdraw(): accepts the amount and updates the principal as p = p – amt
void display(): displays the details of the customer
Assume that the super classBank has been defined.Using the concept of inheritance, specify
the class Account giving details of the constructor(…), void deposit(), void withdraw() and
void display(). The super class and the main function need not be written.
Q.6A
A library issues books on rental basis at a 2% charge on the cost price of the
bookper day. As per the rules of the library, a book can be retained for 7 days
without any fine. If the book is returned after 7 days, a fine will also be charged for
the excess days as per the chart given below:
Design a class Library and another class Compute to perform the task. The details
of the two classes are given below:
Class name : Library
Member functions:
Member functions:
Q 6B
A super class Worker has been defined to store the details of a worker. Define a subclass
Wages to compute the monthly wages of the worker. The details/specifications of both
classes are given below:
Class Name Worker
Data Members/Instance Variables:
Name Stores the name of the worker.
Basic Stores the basic pay in decimals.
Member Functions:
Worker(…) Parameterised constructor to assign values to data
members.
void display() Displays the worker's details.
Member Functions:
Wages(…) Parameterised constructor to assign values to data
members of both the classes.
Double overtime() Calculates and returns the overtime amount as
(hours x rate).
void display() To count the frequency of the word "and".
Specify the class Worker, giving details of the constructor and void display(). Using the
concept of inheritance. specify a class Wages giving details of the constructor, double
overtime() and void display().Write an appropriate main() function.
Q 6C. A class Employee contains employee details and another class Salary calculates the
employee’s net salary.
Member functions:
Data member :
Member functions:
members.
DA = 10% of basic
PF = 8% of salary
Specify the class Employee giving details of the constructors and member function void
display( ). Using the concept of Inheritance specify the class Salary giving details of
constructors and the member function void calculate( ). The main function need not be
written.
Circle
Cylinder
Radius is stored in Circle class while height is stored in Cylinder class. Circle class computes
the base area while lateral area and total area are computed in Cylinder class. Create
another class (Main) to implement these.
QExtra).Write a program to implement class hierarchy
Circle
Sphere
The sphere class overrides two methods of Circle class : showCharacteristics() and
calculateArea(), and has an additional method calculateVolume(). Also write a class Test that
has main() method which creates objects of Circle and Sphere classes and tests them.
Circle
Sphere
The sphere class overrides two methods of Circle class : showCharacteristics() and
calculateArea(), and has an additional method calculateVolume(). Also write a class Test that
has main() method which creates objects of Circle and Sphere classes and tests them.
Date: 10/8/2020
co-ordinate and y as the y co-ordinate. The co-ordinates of midpoint of two points P1(x1,y1)
and
x1 x 2
x
2 ,
y1 y 2
y
2
Data members
Member functions:
Point midpoint(Point A, Point B): calculates and returns the midpoint of the two points A and
B.
Specify the class Point giving details of the constructor( ), member functions void readPoint(),
Point
midpoint(Point, Point) and void displaypoint() along with the main function to create an
object and call
the functions accordingly to calculate the midpoint between any two given points.
Q.11 A class Mixer has been defined to merge two sorted integer arrays in ascending order.
Some of the members of the class are given below:
Class name : Mixer
Data members/instance variables:
intarr[] : to store the elements of an array
int n : to store the size of the array
Member functions:
Mixer(intnn) : constructor to assign n = nn
void accept() : to accept the elements of the array in ascending order
without any duplicates
Mixer mix( Mixer A) : to merge the current obect array elements with the
parameterized array elements and return the resultant obect
void display() : to display the elements of the array
Specify the class Mixer, giving details of the constructor(int), void accept(), Mixer mix(Mixer)
and void display(). Define the main() function to create an obect and call the function
accordingly to enable the task.
Q12. The International Standard Book Number (ISBN) is a unique numeric book identifier
which is printed on every book. The ISBN is based upon a 10-digit code. The ISBN is legal if
1*digit1 + 2*digit2 + 3*digit3 + 4*digit4 + 5*digit5 + 6*digit6 + 7*digit7 + 8*digit8 + 9*digit9
+ 10*digit10 is divisible by 11.
Example: For an ISBN 1401601499
Sum=1*1 + 2*4 + 0*0 + 4*1 + 5*6 + 6*0 + 7*1 + 8*4 + 9*9 + 10*9 = 253 which is divisible by
11.
Write a program to:
(i) input the ISBN code as a 10-digit number
(ii) If the ISBN is not a 10-digit number, output the message “Illegal ISBN” and terminate the
program
(iii) If the number is 10-digit, extract the digits of the number and compute the sum as
explained above.
If the sum is divisible by 11, output the message “Legal ISBN”. If the sum is not divisible by
11, output the message “Illegal ISBN”.
Q.13 Write a Program in Java to input a number and check whether it is a Kaprekar number
or not.
Note: 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
Example 2: 45
452 = 2025, right-hand piece of 2025 = 25 and left hand piece of 2025 = 20
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.
Q.14Write a Program in Java to input 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).
The first few such numbers are 4, 22, 27, 58, 85, 94, 121.....
Example 1.
Sample data:
Q.15 Write a menu driven Program in Java to input a number and check whether i) it is an
Automorphic number or not and (ii) it is a Disarium number or not and (iii) it is an Armstrong
number or not.
Q.16 Write a Program in Java to find all Twin Primes numbers between 10 and 1000.
Write a Program in Java to print all the Twin Prime numbers within a given range.
Note: Twin Prime numbers are a pair of numbers which are both prime and their difference
is 2.
Q.19 Write a Program in Java to input a number and check whether it is a Unique
Number or not.
Note: A Unique number is a positive integer (without leading zeros) with no duplicate
digits. For example 7, 135, 214 are all unique numbers whereas 33, 3121, 300 are not.
Q.20 Write a Program to check whether a number is a Keith number.
Write a Program in Java to input a number and check whether it is a Keith Number
or not.
Note: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.
Some keith numbers are: 14 ,19, 28 , 47 , 61, 75, 197, 742, 1104, 1537……………
Q. 21
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. Write a program 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. Test
your program for the following data and some data that you have coded, using the
rules given above:
Q.22
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.
Q.24ACircular 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.
Accept a positive number N and check whether it is a circular prime or not. The new
numbers formed after the shifting of the digits should also be displayed.
Test your program with the following 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.
Q.25 Write a program in Java to display the Floyd’s Triangle as given below, for N number of
rows. Also note that the value of N is to be entered by the user. You may input from the user
using either the java.io package or java.util package. Name the class as
FloydsTriangle.
INPUT:5
OUTPUT:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
Q.26
Write a program in Java to generate and print lucky numbers, less than a given
number N, where the value of N is to be entered by the user of the program. If the
user enters the value of N as 10, then we have the following sequence of natural
numbers:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
Now, removing every 2nd number from this sequence leaves us with:
1, 3, 5, 7, 9
Now removing every 3rd number from the current sequence gives us:
1, 3, 7, 9
Removing every 4th number gives:
1, 3, 7
This sequence now remains constant if you attempt to continue this process.
Hence lucky numbers less than 10 are 1, 3, and 7.
Example:
INPUT: N = 10
OUTPUT: 1, 3, 7
INPUT: N = 25
OUTPUT: 1, 3, 7, 13, 19
Q.27A happy number is a number in which the eventual sum of the square of the digits of
the number is equal to 1.
Example:
28 = ( 2 )^2 + ( 8 )^2 = 4 + 64 = 68
Design a class happy to check if a given number is a happy number. Some of the members of
the class are given below:
Member functions :
int sum_sq_digits(int x) : returns the sum of the square of the digits of the number x
void ishappy( ) : checks if the given number is a happy number by calling the function
sum_sq_digits(int) and displays an appropriate message
Specify the class Happy giving details of the constructor( ), void getnum(int),
intsum_sq_digits(int) and void ishappy( ). Also define a main( ) function to create an object
and call the methods to check for happy number.
Q.28
Write a program to input a natural number less than 1000 and display it in words. [Note we
have solved the program for numbers in the range [1-9999]
Test your program for the given sample data and some random data.
Sample Data:
Input: 29
Input: 119
Input: 500
Q.29
An Emirp number is a number which is prime backwards and forwards. Example: 13 and 31
are both prime numbers. Thus, 13 is an Emirp number.
Design a class Emirp to check if a given number is Emirp number or not. Some of the
members of the class are given below:
Member functions:
intisprime(int x) : check if the number is prime using the recursive technique and return 1 if
prime otherwise return 0
void isEmirp() : reverse the given number and check if both the original number and the
reverse number are prime, by invoking the function isprime(int) and display the result with
an appropriate message.
Specify the class Emirp giving details of the constructor(int), intisprime(int) and void
isEmirp(). Define the main() function to create an object and call the methods to check for
Emirp number.
Q.30
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.
Instance variables: m, n
public static void Gen3DPalPrime() //insert a 1-D palprime number between 11 and test for
primeness. Eg, insertion of 3 and 5 between 11 yields palprimes : 131, 151
public static void Gen4DPalPrime() //insert a 2-D palprime number in place of middle two
zeroes in 1001 and test for primeness.
public static void Gen5DPalPrime() //insert some 3-D palprimes in 11 eg., insertion of
131,383,797 yields these palprime numbers : 11311, 13631, 17971.
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
101,131,151,181,191,313,351,373,383,727,757,787,797,919,929
Example 2:
INPUT:
M=100
N=5000
Q.31
Composite number:
For example: 10
Factors are: 1, 2, 5, 10
Magic number:
A magic number is a number in which the eventual sum of the digits is equal to 1
For example: 28=2+8=10=1+0=1
172=1+7+2=10
10=1+0=1
Instance variable : m, n
Methods:
MagicCompo()
int Sum_of_digits(int)
int isPrime(int)
boolean isMagic(int)
void display()
void main()
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 the frequency, in the format specified below.
Test your program with the sample data and some random data:
Example 1:
INPUT:
m = 10
n = 100
OUTPUT:
THE COMPOSITE MAGIC INTEGERS ARE:
Example 2:
INPUT:
m = 1200
n = 1300
OUTPUT:
Example 3:
INPUT:
m = 120
n = 99
OUTPUT:
INVALID INPUT
Q.32
Write a Program 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.
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
NO. OF 1’s : 4
Example 2
INPUT : 26
NO. OF 1’s : 3
OUTPUT : NOT AN EVIL NUMBER
Q.33
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.
Write a program 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.
SAMPLE DATA
INPUT:
N=9
OUTPUT:
4+5
2 + 3+ 4
INPUT:
N = 15
OUTPUT:
7 +8
1 +2+ 3+ 4+ 5
4 +5+ 6
INPUT:
N = 21
OUTPUT:
10+ 11
1+ 2+ 3+ 4+ 5+ 6
6+ 7+ 8
Q35. A square matrix [][] where no of rows >2 and < 9. Sort each row in ascending order
using any general sorting algorithm and print the original as well as the changed matrix.
Q35A.
A two-dimensional character array is defined as A[3…6, -2…2]. If the array is stored in Row-
major order, determine the address of A[5, 1], given the base address as 1200.
Q35B.
How would array appear in memory, if : (I) Row-Major technique is implemented. (ii) Column-
major technique is implemented.
Q35C.
X is 2-D array [10 x 5]. Each element of the array is stored in 2 memory locations or requires 2
words of storage space for each element. If X[1, 1] begins at address 150, find the location of X[3,
4]. Use the formula for calculations. (The arrangement is in row-major).
Q35D.
If an integer array Z[-20…20, 10…35] is stored in column major order beginning location 500,
determine the location of Z[0,30].
Q35E.
Each element of an array B[-15…20,20…45] requires one byte of storage. If the array is stored in
column major order and the location of B[0, 40] is 1735, find the address of the beginning
location B[0, 0]
Q.36 A square matrix is said to be a Ma ic Square, if the sum of each row, each column and
g
each diagonal is same. Write a program 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
Instance Variables
Methods
Also create method main() that should obtain the value of N and then create and print the
array.
Q.37A.
Q.41 Write a program to a) sort the elements of a 2-D array b) sort the boundary elements
of a matrix c) sort each row of a matrix d) sort each column of a matrix
Specify the class Composite giving details of the constructor, and other methods.
Also define the main() method to create an object and call the methods accordingly to
enable the task.
Q. 44
Specify the class Shift giving details of the constructor, void input(), void cyclic(Shift)
and void display(). Define the main() function to create an object and call the
methods accordingly to enable the task of shifting the array elements.
Q.45
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:
(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.
(c) Display the original matrix, rearranged matrix and only the diagonal elements of
the rearranged matrix with their sum.
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
Q.46
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 :
@ $ $ $
@
! @ $
@ !
! !
@ ! !
! @ $
@ !
@ $ $ $
@
Example 3
ENTER SIZE : 65
OUTPUT : SIZE OUT OF RANGE
Q.47
Write a program 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.
Test your program for the following data and some random data:
Example 1
INPUT :
M=3
OUTPUT :
ORIGINAL MATRIX
OUTPUT :
ORIGINAL MATRIX
Q 47B
A class Collection contains an array of 100 integers. Using the following class description
create an array
with common elements from two integer arrays. Some of the members of the class are given
below:
Data members
Member functions
void arrange() : sort the array elements of the object containing common elements in
ascending order
using any sorting technique.
Specify the class Collection giving the details of the constructors, void inparr() and void
arrange(),
Collection common(Collection). You need not write the main Function.
Q47C
Q 47D
A class PrimeFac contains an array of 50 integers. Some of the members of the class are
given below:
Class name : PrimeFac
Data members
num[] : array to store integers.
freq[] : array to store the frequency of prime factors of numbers.
Member functions
PrimeFac() : constructor to inititalize array elements to 0.
void enter() : to enter values into array num[]
void frefac() : to determine the frequency of prime factors of the numbers stored in num[]
and assign it to freq[].
void disp() : to display both the arrays.
Specify the class PrimeFac giving details of the constructor, void enter(), void frefac() and
void disp().You
need not write the main function.
Q 47D1
Write a Java program that accepts the value of N (an integer) and creates N x N boolean
array a[ ] [ ] such that a[I][j] ids true I I and j are relatively prime (I.e., have no common
factors) and false otherwise. The class specifications are as follows:
Class name : RelPrime
Instance Variables : boolean array of N x N.
Member functions
void create(int n) : create boolean array a[ ][ ] so that
a[I][j]=true, if I,j are relatively prime
=false, otherwise.
int gcd() : determines the greatest common divisor off two numbers.
void disp() : prints the boolean array a[][].
A constructor method to create array.
Also write main() method that accepts value of N(<100) and then implements the above
mentioned functionality.
Q 47D2
array.
Q 47D3
Write a Java program to perform Bubble Sort in a given 1-D array of integers.
Q 47D4
Write a Java program to perform selection sort in a given 1-D array of integers.
Q 47D5
Q 47D6
Q 47D7
Write a Java program that adds two binary numbers and returns their binary sum as per the
following rules:
0+0=0
0+1=1
1+0=1
1+1=10 (here 1 is carry bit of 10)
1+1+1=11 (here 1 is carry bit of 11)
You can use arrays to hold binary digits. The class specifications are:
Class name : BinNumbers
Methods:
long BinAdd(long A, long B) : adds two binary numbers received in A and B
Write method main()that reads the two binary numbers and invokes BinAdd() to get their
sum.
Q 47D8
Christian Goldback hass conjectures for N < 1014 that every even N>2, can be represented as
sum of two primes. For example, 18=5+13.
Write a Java program that readsN which should be an even number > 2 and represents it as
the sum of two primes.
Q 47D9
Write a Java program to find the longest consecutive sequence of integers with no primes.
The program should accept a number N and print out the largest block of integers between
2 and N with no primes.
Q 47D10
Write a Java program to find the number of prime numbers <= N where accept N from the
user. Use the method Sieve of Erathosthenes to find prime numbers.
To get the prime numbers in the range 2..N, you can use a simple and interesting method
known as Sieve of Erathosthenes. It works as follows :
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
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100
Sequentially write down the integers from 2 to the highest number n you wish to include in
the table. Cross out all the numbers >2 which are divisible by 2 (every second number). Find
the smallest remaining number >2. It is 3. So cross out all the numbers > 3which are divisible
by 3 (every third number). Find the smallest remaining number > 3. It is 5. So cross out all
numbers > 5 which are divisible by 5 (every fifth number).
Continue until you have crossed out all numbers divisible by └√n┘,where └x┘ is the floor
function. The numbers remaining are prime. This procedure is illustrated in the above
diagram which sieves up to 50, and therefore crosses out composite numbers up to
└√50┘=7.
Q 47D11
You can generate random numbers in the range 0 to 1 using Math.random() method. If you
want to generate random numbers in a range 7(L) to 23(U) then you can use the method as :
Math.random() * (U-L+1)+L
Where L is the lower limit ie, 7; U is the upper limit ie 23
Using this formula, generate a 1D double type array a in the range 10-50 after asking the
user to specify its length.
Then perform the following actions on the array
(i) Display array elements
(ii) Find maximum element of the array
(iii) Compute array average
(iv) Copy array to another array b
(v) Reverse the second array
(vi) Display second array
(vii) Calculate dot product of two arrays as :
Σa[I]*b[I]
Q 47D12
The B-by-N Hadamard H(N) matrix is a boolean matrix with the remarkable property that
any two rows differ in exacgly N/2 bits.
H(1)
T
H(2)
TT
T0
H(4)
TTTT
T0T0
TT00
T00T
Write a program that takes the value N and prints H(N). Assume that N is a power off 2.
Instance Variable :
boolean[ ][ ] H;
int N;
Methods:
Hadamard(int n)
void createHadamard()
void print();
public static void main(String[ ] args)
Q 47E
Lucky Numbers are those that are generated by a sieving process similar to that of Sieve or
Eratosthenes, consider a list of natural numbers that starts with 1
1, 2, 3, 4, 5, 6, 7, 8, 9, 10 now removing every second element we get
1, 3, 5, 7, 9 now removing every third we get
1, 3, 7, 9 now removing every fourth we get
1, 3, 7 we can no longer remove the fifth so the survivors are 1, 3 and 7 which are Lucky
numbers from 1 to 10.
WAP to implement the same using arrays and display the Lucky numbers from 1 to 10
Q47F The result of a quiz competition is to be prepared as follows:
The quiz has five questions with four multiple choices (A, B, C, D), with each question
carrying 1 mark for the correct answer. Design a program to accept the number of
participants N such that N must be greater than 3 and less than 11. Create a double
dimensional array of size (Nx5) to store the answers of each participant row-wise.
Calculate the marks for each participant by matching the correct answer stored in a single
dimensional array of size 5. Display the scores for each participant and also the participant(s)
having the highest score.
Note: Array entries are line fed (i.e. one entry per line)
Test your program with the sample data and some random data:
Example 1
INPUT : N = 5
Participant 1 D A B C C
Participant 2 A A D C B
Participant 3 B A C D B
Participant 4 D A D C B
Participant 5 B C A D D
Key: B C D A A
OUTPUT : Scores :
Participant 1 D A B C C
Participant 1 = 0
Participant 2 = 1
Participant 3 = 1
Participant 4 = 1
Participant 5 = 2
Highest score: Participant 5
Example 2
INPUT : N = 4
Participant 1 A C C B D
Participant 2 B C A A C
Participant 3 B C B A A
Participant 4 C C D D B
Key: A C D B B
OUTPUT : Scores :
Participant 1 = 3
Participant 2 = 1
Participant 3 = 1
Participant 4 = 3
Highest score:
Participant 1
Participant 4
Example 3
INPUT : N = 12
OUTPUT : INPUT SIZE OUT OF RANGE.
Q.48 Design a class Sort which enables a word to be arranged in alphabetical order. The
details of the members of the class are given below :
Data members :
Member functions:
Sort () : default constructor
void arrange() : to arrange the word in alphebetical order using any standard
sorting technique.
void display( ) : displays the original word along with the sorted word
Specify the class Sort giving details of the constructor, void readword( ), void arrange( )
and void display( ). Define the main( ) function to create an object and call the functions
accordingly to enable the task.
Q.48A.
Program to check whether a string is palindrome or not. The program must have the
following functions:
public static void main(String args[]) /* input a string and test to see if it is a palindrome*/
public static boolean isPalindrome2(String s)/* Returns true if the string is a palindrome
when case is ignored. */
Q.48B.
Implement a class StringS that has a data member as String text. The class also contains a
method extracText() that recceives a word as parameter. The passed word appears at least
two times in the text. Method extracText() finds the first and last occurrence of the passed
word in the text and returns the text from between the two occurrences.
Sample Input/Output
This is true that often and mostly true things remain hidden.
true
Write a Java program to implement a class Strings with the following method swapPairs that
accepts a String as a parameter and returns the String with each pair of adjacent letters
reversed. If the String has an odd number of letters, the last letter is unchanged. For
example, the call swapPairs(“forget”) should return “ofgrte” and the call swapPairs(“hello
there”) should return “ehllo htree”.
The class also has method main() that accepts a string and calls swapPairs() method to swap
pairs of characters in the passed string.
Q.49 Write a program to swap two strings without using third variable.
Example:
INPUT: HELLO WORLD
OUTPUT: HELO WRD
Example:
INPUT: Jaaavvvvvaaaaaaaaaaaa
OUTPUT: Java
INPUT: Heeeeiiiissssggoiingggggggggg
OUTPUT: He is going
Write a Program in Java to input a Date in ddmmyyyy 8-digit format and print it in:
1) dd/mm/yyyy format
2) dd, month name, yyyy format
Input: 01011943
Output:
01/10/1943
1 January, 1943
Q.54Question:
A sentence in the Special Fashion can be printed by taking two integers (not beyond total
number of words in the sentence or less than 1). These integers tell the word number of the
sentence. Replace only those words present at those given integer places by the next
character in a circular fashion according to the English Alphabets. If both the integers are
same then replace only one word. let us consider the following examples:
Input Integers: 2, 4
(i.e. word number 2 and 4 have been replaced by the next characters in a circular fashion)
Input Integers: 3, 3
Write a case sensitive program that reads a sentence from console (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.
In the first example given above, word number 2, i.e. has is replaced by next characters and
hence it becomes ibt . Similarly, word number 4, i.e. tide is replaced by next characters and
hence it becomes ujef .
Input a piece of text consisting of sentences. Assume that there will be a maximum of 10
sentences in a block.
(i) Obtain the length of the sentence (measured in words) and the frequency of vowels in
each sentence.
(ii) Generate the output as shown below using the given data
Sample data:
INPUT HELLO! HOW ARE YOU? HOPE EVERYTHING IS FINE. BEST OF LUCK.
OUTPUT
1 2 1
2 5 3
3 8 4
4 3 3
----------------------------------------------------------
1 VVVVVV
WWW
2 VVVVVVVVVVVVVVV
WWWWWWWWW
3 VVVVVVVVVVVVVVVVVVVVVVVV
WWWWWWWWWWWW
----------------------------------------------------------
Q.56 Input a paragraph containing 'n' number of sentences where (1<=n<=4). The words are
to be separated with single blank space and are in upper case. A sentence may be
terminated either with a full stop (.) or question mark (?). Perform the followings:
(i) Enter the number of sentences, if it exceeds the limit show a message.
Example 1:
INPUT:
1
Enter sentences:
TO BE OR NOT TO BE.
OUTPUT:
WORD FREQUENCY
OR 1
NOT 1
TO 2
BE 2
Q.57
S0 = “a”, S1 = “b”, Sn = S(n-1) + S(n-2) where ‘+’ denotes concatenation. Thus the sequence is:
Design a class FiboString to generate Fibonacci strings. Some of the members of the class are
given below:
Member functions/methods:
void generate() : to generate and print the fibonacci strings. The sum of (‘+’ i.e.
concatenation) first two strings is the third string. Eg. “a” is first string, “b” is second string
then the third string will be “ba” and fourth will be “bab” and so on.
Specify the class FiboString, giving details of the constructor(), void accept() and void
generate(). Define the main() function to create an object and call the functions accordingly
to enable the task.
Output:
Q.58 Input a word in uppercase and check for the position of the first occurring vowel and
perform the
following operation.
i) Words that begin with a vowel are concatenated with “Y” . For example, EUROPE becomes
EUROPEY.
ii) Words that contain a vowel in between should have the first part from the position of the
vowel till end, followed by the part of the string from beginning till position of the vowel and
iii) Words which do not contain a vowel are concatenated with “N”. For example, SKY
becomes
SKYN.
Design a class Rearrange using the description of the data members and member functions
given below:
Data members
Member functions
void convert() : converts the word into its changed form and stores it in string Txt
Specify the class Rearrange giving the details of the constructor(), void readword(), void
convert() and
void display(). Define a main function to create an object and call the function accordingly to
enable the
task.
Q58A
Write a program to search for a string in an ordered array (with elements in ascending order)
using binary search.
Q58A1
For an array containing the terms 2,4,6, and so on up to 28 in that order, draw a trace/dry
run showing which elements are examined if you search for 21 using a binary search.
Q58A2
Write a Java program that accepts a String and prints the letters of the string, separated by
dashes, along with the reversed string, separated by dashes.
U-s-e-f-u-l
l-u-f-e-s--U
Q58A3
Write a Java program that accepts a student’s first name, middle name, last name and age. It
then generates a password as per following specifications:
<first and last letter of lastname> <first digit of age> <first and last letter of firstname>
<second digit of age> <first and last letter of middle name>
ie, for a name “Shama Mohan Bhandari” and age 24, it should generate :
Bi2Sa4Mn
Q58A4
Write a Java program that prompts a user for a mobile number of the form ddd-dddd ddddd,
where d is a digit.
The first three digits signify country-code. Display the phone number in the following format :
Sample Input/Output :
Q58B
A subsequence of a given sequence is the given sequence with just some elements left
out (order should be from left-to-right, not necessarily consecutive. For example, BCBA is a
subsequence of ABCBDAB. Read in two string sequences and determine whether the first
string sequence is a subsequence of the second string sequence.
Q 58C
Q 58D
Design a class Alpha which enables a word to be arranged in ascending order accordingly to
its alphabets.
The details of the members of the class are given below :
Class name : Alpha
Data members/ instance variables:
Str : to store a word
Member functions :
Alpha( ) : default constructor
void readword( ) : to accept the inputted word
void arrange( ) : to arrange the word in alphabetical order using any standard
sorting technique.
void disp( ) : display the word.
Specify the class Alpha giving details if the constructor and member functions void readword
( ), void
arrange( ), void disp ( ) and defining the main ( ) function to create an object and call the
function in order to execute the class by displaying the original word and the changed word
with proper message.
Q58E
Write a program to accept a plain text of length L, where L must be greater than 3 and less
than 100.
Test your program with the sample data and some random data:
Example 1
INPUT : Hello! How are you?
OUTPUT : The cipher text is:
Uryyb? Ubj ner lbh?
Example 2
INPUT : Encryption helps to secure data.
OUTPUT : The cipher text is:
Rapelcgvba urycf gb frpher qngn.
Example 3
INPUT : You
OUTPUT : INVALID LENGTH
Topic #11 Recursion - Submission Date: 10/11/2020
Q.61
Data members
Member functions
void calculate() : to calculate the sum of the series by invoking the recursive functions
repeatedly
Q.63 Program to print GCD and LCM of two numbers using recursion.
Member functions/methods:
The Combination function C(n , k) gives the number of different (unordered ) K – elements
Subsets that can be
Design a class Combination to implement this formula. Some of the data members and
member functions are
given below.
n : integer number
k : integer number
Member functions :
(a) Specify the class Combination, giving details of the Constructor and member functions
void read( ), int
fact(int) and void compute( ). Also write the main( ) function to create an object and call the
member function
(b) Give any two appropriate differences between recursion and iteration process. [2]
Q66C
Design a class Change to perform string related operations. The details of the class are given
below:
Member Functions:
char caseconvert(char ch) : converts the case of the character and returns it
(a) Specify the class Change, giving details of the constructor, member functions void
inputword(), char caseconvert(char ch), void recchange(int) and void display. Define the
main() function to create an object and call the function accordingly to enable the above
change in the given word.
Q 66D
Member Functions:
(a) Specify the class Convert, giving details of the constructor, member functions void
inputword(), char extdigit(int), void num_to_words(int).The main() function need not be
written.
Q66E
Design a class change to convert a decimal number to its equivalent in base 16 and to
convert it back to
its decimal form. Eg.(i) The decimal number 35 is 23 in base 16. ii) The decimal number 107
is 6B in base
16.
Data members
Member functions
Specify the class change giving the details of the constructor and the functions void input(),
void
hexadeci(int) and void decihexa(). The main function need not be written.
QExtra)
Class Binary contains an array of n integers (n<=100) that are already arranged in ascending
order. The
subscripts of the array elements vary from 0 to n-1. The data members and member
functions of class
Data members
n : size of array
Member functions:
Binary(int nn) : constructor to initialize the size n to nn and the other instance variables.
int binary_search(int v) : returns the location of the value(v) to be searched in the list by
binary search method using the recursive technique. The function returns -1 if the number is
not present in the given list.
a) Specify the class Binary giving details of the constructor, void readdata() and int
binary_search(int). you need not write the main function.
Q.67 Define a class Repeat which allows the user to add elements from one end (rear)
and remove elements and remove elements from the other end (front) only.
Data members
elements
cap : stores the capacity of the array
Member functions
a) Specify the class Repeat giving details of the constructor(int), member function
void
Q.68A bookshelf is designed to store the books in a stack with LIFO (Last In First
Out) operation. Define a class Book with the following specifications:
Class name: Book
Data members/instance variables:
name[]: stores the names of the books
point: stores the index of the topmost book
max: stores the maximum capacity of the bookshelf
Methods/Member functions:
Book(int cap): constructor to initialize the data members max = cap and point = -1
void tell(): displays the name of the book which was last entered in the shelf. If there
is no book left in the shelf, displays the message “SHELF EMPTY”
void add(String v): adds the name of the book to the shelf if possible, otherwise
displays the message “SHELF FULL”
void display(): displays all the names of the books available in the shelf Specify
the class Book giving the details of ONLY the functions void tell() and void
add(String). Assume that the other functions have been defined.
The main function need not be written.
10/11/2020
[Question 1] ISC 2016 Computer Science Practical
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
Example:
131311113
Hence, 131 is a circular prime.
Test your program with the sample data and some random data:
Example 1
INPUT:
N = 197
Example 2
INPUT:
N = 1193
Example 3
INPUT:
N = 29
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
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
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
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
valid ISBN.
3.
4.
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
valid ISBN.
5.
Design a program to accept a ten digit code from the user. For an invalid inout,
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
OUTPUT : SUM = 99
Example 2
Example 3
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.
Examples
Input: 29
Output: TWENTY NINE
Input: 17001
Output: OUT OF RANGE
Input: 119
Output: ONE HUNDRED AND NINETEEN
Input: 500
Output: FIVE HUNDRED
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 =14000500 X 1 =500100 X 3 =30050 X 1 =505 X 1 =51 X 1 =1
Example 2
EXAMPLE 2:
INPUT: 235001
OUTPUT: INVALID AMOUNT
Design a program to accept a day number (between 1 and 366), year (in 4 digits)
from the user to generate and display the corresponding date. Also accept 'N'
(1<=N<=100) from the user to compute and display the future date corresponding
to 'N' days after the generated date. Display error message if the value of the day
number, year and N are not within the limit or not according to the condition
specified.
Test your program for the following data and some random data.
Examples
INPUT : DAY NUMBER : 233 YEAR : 2008 DATE AFTER(N) : 17
OUTPUT: 20TH AUGUST 2008 DATE AFTER 17 DAYS : 6TH SEPTEMBER 2008
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).
The first few such numbers are 4, 22, 27, 58, 85, 94, 121.....
Examples
666 Prime factors are 2, 3, 3 and 37
Sum of the digits are (6+6+6) = 18
Sum of the digits of the factors (2+3+3+(3+7) = 18
Sample data:
Input 94 Output SMITH Number
Input 102 Output NOT SMITH Number
Write a program to accept a date in the string format dd/mm/yyyy and accept
the name of the day on 1st of January of the corresponding year. Find the day
INPUT DATE DAY ON 1ST JANUARY OUTPUT DAY FOR INPUT DATE4/9/1998
THURSDAY FRIDAY31/8/1999 FRIDAY TUESDAY6/12/2000
SATURDAY WEDNESDAY
The program should include the part for validating the inputs namely the date
Test your program for the following data and some random data
SAMPLE DATA
INPUT N = 15
OUTPUT 7 8
12345
full stop. The words in this string are assumed to be separated by one or more
blanks.
Arrange the words of the input string in descending order of their lengths. Same
length words should be stored alphabetically Each word must start with an
Test your program for the following data and some random data.
SAMPLE DATA:
Write a program that inputs the names of people into two different arrays, A and B.
Array A has N number of names while Array B has M number of names, with no
duplicates in either of them. Merge array A and B into a single array C, such that
the resulting array is sorted alphabetically.
Display all the three arrays, A, B and C, sorted alphabetically. Test your program
for the given data and some random data.
SAMPLE DATA
INPUT
OUTPUT
The input in this problem will consist of a number of lines of English text
consisting of the letters of the English alphabet, the punctuation marks (')
apostrophe, (.) full stop, (,) comma, (;) semicolon, (:) colon and white space
characters (blank, newline). Your task is to print the words of the text in reverse
right this solve will you smart are you If problem this illustrate to text of piece sample a is This
That is, the lines are printed in reverse order.
INPUT FORMAT:
The first line of input contains a single integer N (<=20), indicating the number
of lines in the input. This is followed by N lines of input text. Each line should
OUTPUT FORMAT:
Output the text containing the input lines in reverse order without punctuation
A sentence is terminated by either ".", "!" or "?" followed by a space. Input a piece
of text consisting of sentences. Assume that there will be a maximum of 10
sentences in a block.
1. Obtain the length of the sentence (measured in words) and the frequency of vowels in
each sentence.
2. Generate the output as shown below using the given data
Examples
INPUT:
number of rows and n is the number of columns such that both m and n must
Allow the user to input positive integers into this matrix. Perform the following
1. Sort the elements of the outer row and column elements in ascending order
using any standard sorting technique.
2. Calculate the sum of the outer row and column elements.
3. Output the original matrix, rearranged matrix, and only the boundary
elements of the rearranged array with their sum.
Test your program for the following data and some random data.
Example 1
REARRANGED MATRIX :
1 3 4
9 2 5
8 7 6
BOUNDARY ELEMENTS :
1 3 4
9 5
8 7 6
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.
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:
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
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:
Example 1:
INPUT : M = 3
4 16 128 2 146 1 3
OUTPUT :
ORIGINAL MATRIX
4 16 128 2 146 1 3
12 16 414 2 8
3 1 6
Example 2:
INPUT : M = 22
positive integer and represents row and column. M should be greater than 2
and less than 10.Accept the value of M from user. Display an appropriate
INPUT: M=31 2 32 4 53 5 6
OUTPUT:
Original matrix1 2 32 4 53 5 6
Example 2:
INPUT: M=4
OUTPUT:
Original matrix:7 8 9 24 5 6 38 5 3 17 6 4 2
Example 3:
INPUT: M=12
OUTPUT:
Matrix size is out of range
[Question 2] ISC 2015 Computer Science Practical
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 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:
3.
Original matrix Rotated matrix
1 2 3 7 4 1
4 5 6 8 5 2
7 8 9 9 6 3
4.
5.
Find the sum of the elements of the four corners of the matrix.
6.
Test your program for the following data and some random data:
Example 1
INPUT: M=3
3 4 92 5 81 6 7
OUTPUT:
ORIGINAL MATRIX
3 4 92 5 81 6 7
Example 2
INPUT: M=4
1 2 4 92 5 8 31 6 7 43 7 6 5
OUTPUT:
ORIGINAL MATRIX
1 2 4 92 5 8 31 6 7 43 7 6 5
Example 3
INPUT: M=14
OUTPUT:
SIZE OUT OF RANGE
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
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
Example 2
INPUT :M = 5
7 4 1 9 5 8 2 6 10 1913 1 3 5 110 0 5 12 16 1 8 17 6 8
OUTPUT:
ORIGINAL MATRIX
7 4 1 9
5 8 2 6
10 1913 1 3
5 110 0 5
12 161 8 17 6 8
REARRANGED MATRIX
7 4 1 9 5 8 0 1 2 1913 3 5 5 110 6 10 12 161 8 17 6
8
DIAGONAL ELEMENTS
7 5
0 2
5
6 121 8
Example 3
INPUT: M = 3
OUTPUT: THE MATRIX SIZE IS OUT OF RANGE.
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.
Example 1
INPUT: Intelligence plus character is education.
OUTPUT:
Intelligence Plus Character Is Education.
Example 2
INPUT: God is great.
OUTPUT:
God Is Great
OUTPUT:
Invalid Input
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 "!".
Test your program with the sample data and some random data:
Example 1
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
Example 1
Example 2
Example 3
Input a paragraph containing 'n' number of sentences where (1<=n<=4). The words
are to be separated with single blank space and are in upper case. A sentence may
be terminated either with a full stop (.) or question mark (?).
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
separated with a single blank space and are in lower case. Arrange the words
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
Examples
Test your program for the following data and some random data.
Given a square matrix list [ ] [ ] of order ‘ n ’. The maximum value possible for
‘ n ’ is 20. Input the value for ‘ n ’ and the positive integers in the matrix and
perform the following task:
Sample data:
INPUT:
N=3
List [] [ ] = 5 1 3
746
982
OUTPUT:
513
746
982
Sorted list
135
467
289