The document outlines various programming tasks and exercises, primarily focused on Java, including array manipulation, matrix operations, and string processing. It provides examples of input and expected output for each task, emphasizing the importance of sorting, encoding, and data structure management. The tasks range from basic operations to more complex algorithms involving user input and data analysis.
The document outlines various programming tasks and exercises, primarily focused on Java, including array manipulation, matrix operations, and string processing. It provides examples of input and expected output for each task, emphasizing the importance of sorting, encoding, and data structure management. The tasks range from basic operations to more complex algorithms involving user input and data analysis.
the expression or statement
at each oy
wnat ) 2 M OF the fotoing
on (a) 242
“3?
4 programs based on Single ang Doup)
ve am to input and store 1 jn Dimensi
jrite a POR tne tegers (ns gy ONAL Area
i a amber eh ees outa ae i
i Subse
sei ifferent ci ipted variable
oan ney in two different columns, ain number ]
16
“Number ba)
2 :
14
16 2
18 2
20 3
ite a program to accept a set of n integers (where n > 0)
x ‘range the elements of the array such that the lowest number appears in the
or f the array, next lower number in the right cell of the centre, next lower in
fale cell of the cenize ance process will stop when the highest number
betas appropriate cell. Finally, display the array elements.
ae Seana memory space is less. Hence, you don’t need to create extra array
‘Assume
for the aforesaid task.
) in a single dimensional
‘denomination of an input Se
‘with the bank are of rupees 2000, 500,
; break-up in
mm the user and display the Ort
‘ ven to the higt
ke should be gi
Gf notes. int the amount in
yed]. Also prinroe
fo
as follow
by adding the encrypted value ¢
stial of a word is found by adding eg,
a oem +b a8 eae
i h is terminated by either”. "2" or w yy»
Accept 8 erieated by’ single space. Decode the words according to Sih
re ctical order. Output the result in the fey boat
them in alphabetical order. Outp mat
le 1 Input: THE SKY IS THE LIM oS
Output: IS THE THE SKY LIMIT
Example 2 Input: LOOK BEFORE YOU LEAP.
Potential: LOOK = 53
BEFOR.
YOU = 61
LEAP = 34
Output: LEAP BEFORE LOOK YOU
Prog. 5: A Company manufacturing packaging cartons in four sizes, ie, c
6 boxes, 12 boxes, 24 boxes and 48 boxes. Design a progran
boxes tobe packed (N) by the user (maximum up to 1000 box
up of the cartons used in the descending order of capacity
given to the highest capacity available). If boxes left are
of capacity 6 should be used.
Test your program with the followi
Example 1:
Sample Input: N=726
Sample Output; 48*15=720
6 *1=6
Remaining boxes= 0
Total number of boxes
Total Number of cartons:
Example 2:
Sample Input: N=149
Sample Output: 49°2~96
24* 1= 24
ing data and some 1
726
6Korat
gare matrix M |
rent characte
mn in the examples. {t
be displayed
Fi
snd ch
sy charac
npot: F
cond Ch
rind Character “”
aracter ‘!
Output:
essse
1@s@!
el!
1es@!
is to be prepared as follows:
multiple choices (A, B, C, D) with each question
Design a program to accept the number of
than 3 and less than 11. Create @ double
dhe answers of each participant row 81S
ing the correct answer stored in
cipant and the
[asc 2016),gma |< 1c | Ae Pee
He a re ine fed (be. one entry pe line) oe
Note: Array entry are weet
Example ws
: let ne
Imps * Pyricipant 1 DAB CC ee
Participant 2A ADC B ei
Participant 3 BAC DB
Participant 4 DAD CB
Participant § BC A DD
Key: BCDAA
Output: Scores: re
Participant es “
Participant 2 se
sara : =
ed | ware
Participant 5 = 1 re
Highest score: participant 5 iS
Example 2 eS
rmple,
Input : N=4 bec
Participant 1 AC C BD
Participant 2 BC AAC
Participant 3 BC BAA
Participant 4C CD DB
Key: ACDBB
Output : Scores:
Participant 1 = 3
Participant 2
; A square |
Participant 3 a, .
Partici 4
tn Write a p
cpa and fill t
B Participant im
xample 3: 4
a * the elem
teas For exam
Output Input Size Out of.
Prog. 8: Write a Program in Java
it is a Lower Tri ;
Lower Tanga gea
the entries above the 1
diagonal must be non
Enter the size of the mn
The Matrixcer Triangul
is Low gular
Meee grom in J2V8 10 INDUt ele
pra in ava 10 INP elements.
2 POE Matrix OF ne i
ne, Sale A scalar matrix is a
2 ate
es
is Scalar
ye Matix
cis the matrix in Which number o Tow: mi
matrix is d n is called Wuare Matri
ase patrix of order n'n is called ® Ma Ste
2 co Dumber of co}
vf program in Java to create a double limensional array o nm) a
the numbers in a circular fashion (antici "2! array Ge I
lock-wise) with re al
taking ® a8 an input. The filling of the elements shout
ld
YH filed as
fal mambers from
Start from outer to
16, then the array bs
+
41] Seale
Asquare matrix is the matrix in which number of rows e
Thus, a matrix of order n'n is called a Square Matrix,
ite a program in Java to create a double dimensional array of ize nxn matrix form
anf fil the cells of matrix in a circular fashion (dock wise) with natural numben
fom 1 to n?, taking n as an input. Input n should be an odd number and filing of
the elements should start from the central cell.
| —Frrexanple, if n=5, then n?=25, then the filled as:
8 uy :
wid be
i, quals the number of columns
so 21
oy
190 af size nxn matrix formnent 2 dn
Ws a rx is the mirror Image of
a" [ite
6
8
19
with the first ‘mxn’ prime
in Java to fill a 2D array
a'r is the number of columas
is the number of rows
53 | 59 | 61 | 67 | 71
Be Ye: Wile a program to create a double dimensional arr
in its (n-1) x (m-1) cells Find and place the
cemob ending cells of last column and last row
lements along with the sum of rows and colui
Sample Input
ay of size nxm, Input the numes
sum of each row and each column
respectively. Finally, display the any
mns.
Sample Output
10 | 15 | 16
15 | 14 | 12
n | 2] 16 |
2 | 10 4
48 51 58the numbers
h column it
ay the a
(@ Write a program to declare a square matrix A] [of onder N (N20,
(6) Allow the user to input positive inte me Loree
sgers into this matrix. Perfe
tasks on the matrix. a
(0) Output the original matrix.
(@ Find the SADDLE POINT for the matrix. A saddle point isan element ofthe
matrix such that it is the minimum element for the row and the mosis
dlement for the column to which it belongs Sse FO iam
“No
unique. If the matrix has no sa eSSage
is alwa dle point, output them
SADDLE POINT”,
(0 If the matrix has a saddle point element then sort tay eae
diagonal in ascending order using insertion sort technique-
should remain unchanged.
lowing data and So!
random data:
Test your program for the foll en
Sample data:
Input: n=4
Matrix A[ JI ]= 2 a
8 2
6
3
n
a2 24 a
aaa
Beerite a program to input N and M number of names in two different
arrays A and B eer such that none of them have duplicate,
the arrays A and B into a single array C, such that the resulting ana
alphabetically. Display all the three arrays
‘Test your program for the followin;
Sample data:
Input:
Si
8 data and some random data,
Enter the names in array A, N=2
Enter the names in array B, M=3
First array: A
pane Output:
al 123 i
Second array: B Input:
Usha x=4
Sachin
fies Output
Output: 42 (
oe Merged array: C Mg. 2 pe mana
i ind the u
John the machi
Sachin and after
Usha Fach log.
Sorted First array:
ly: A
Anil
Us
Loy
Lo12 (base 8)=34 (base 2)
Input:
x=123, y=456
Output:
123 is not equal to 456 in any base between 2 to 20
seeuapat:
i x=42, y=36
Output:
42 (base 7)=36 (base 8)
Manager of a company wants to analyze the
machine usage from the records to
ind the utilization of the machine. He wants to
xenow for how long each user, used
Machine. When the user wants to use the machine, he must login tothe machine
alter finishing the work, he must logoff the machine.
log record consists of:
| Wer Identification numberLogout Time and Date
2:50 21-12
1230
21-12
Login Time and | Logout Time and
| Sy
Date Date ae
ej Poe | Hes
| 20:10 | 20-12 2:50 2142 640
a
| 20-12 1230 2142 2400
ead ro | {os ton ail
} 212 | 1630 | 2042 |
The user who logged in for longest duration
Prog, 23: Write a program to accept a date in the string format dd/mm/yyyy and —_
4 fame of the day on the Ist of January of the corresponding year. Find the day
given date.
Example:
Input :
Date : 5/7/2001
Day on 1st January :
Output :
Day on 5/7/2001 :
MONDAY
THURSDAY
1
Output
Yes, it
Inpu
n=3wnte a program to read n (2<=n,
jnd output ifthe grid represents
the values gt
@ wondrous, stored
output all the prime numbers in the grid en 4 these n by n cats
| iqdex as shown in the output. A natural rngean 8 Wie thei
two divisors. For example, 2, 3,5, 7,11... pets sid
jesored at row index 0 and column index 0 sya Sement of
stored at row index 0 and column index 1 lement in the row ie 24
Tit your program for the following data and some random a
Input: ata:
n=4
16 [a
[6 4
9
ae
Output:
Yes, it represents a wondrous square
Prime Row Index
ee“Ping. 25 Write a program to input two valid dates, each comprising of Da
(2 digits) and Year (4 digits) and calculate the days eed betwee etalg
‘Test your program for the following data values: "een both the «it
(@) FIRST DATE 3 Day a
Month 09
lal
ou have two
ose Yeurchase three
ye a yc devices, more
{orp handling multip
Year 1960 pasden of
SECOND DATE: Day 08 inthe same WAY, during
Month =: 12 smultiple instances, can
Year 1852 | tetus understand the ¢
Output ==: xxxc00K Prog, 1:
these —_.
« ee number | | // Program to check
(6) FIRST DATE : Day 4 10 import java.util.*;
Month o1 public class Prime1
Year 1952 {
SECOND p,
ATE Day 16 Public static void mi
Month 10 {
Year 1952
Output 200000%X FRSC in=new So,
are actual number! | Syst
(these are actual | “Mout.printin(
days elapsed) ms
ya | Nextinty);: 1 eet | 4) L
"Prog. 5 Write a program in Java to accept a string and display the new string after
the characters of each word. ,
Sample Input: Understanding Computer Science
Sample output: gnidnatsrednU retupmoC ecneicS.
Prog. 6 Write a program in Java to accept two strings. Display the new string by aking el
D
character of the first string from left to right and of the second sting fag
Ieft. The letters should be taken alternatively from each string. Assume that thelng
of both the strings are same.
Sample Input: String 1: HISTORY
String 2: SCIENCE
Sample Output: HEICSNTEOIRCYS
Bee: 7: Write a program in Java to accept a four-letter word. Display all the probate
letter combinations such that no letter should be repeated in the output within ud
‘combination.
Sample Input: PARK
Sample Output: PAKR, PKAR, PRAK, APRK, ARPK, AKPR,
Prog. 8: While typing, a typist has created two or more consecutive blank spaces between lt
Words of a sentence. Write a program in Java to eliminate multiple blanks bette?
the words by a single blank.
Sample Input:
Indian Cricket team tour to Australia
Sample Output:
Indian Cricket team tour to Australia
|
and so on
Prog. 9: A new advan:
designed byTINg by tay
rin
me that ie
the probable fe
itput within ed
ind so on.
ces between
blanks bet
40: The input in this question will consis
of the letters of the English alphabet, the Piet eo Brel pe
stop (,) comma, (;) semicolon, () colon and white seen) pesttophe, () full
Your task is to print the words of the text in revere sean sete (lank, new line).
oar fas i to rin the reverse order without any punctuation
For example, Consider the following input text;
This is a sample piece of text to illustrate this question
If you are smart you will solve this right
The corresponding output would read as
ght his solve will you smart are you if question this illustrate to text of piece sample
Note: Individual words are not reversed.
Input Format:
This first line of input contains a single integer n (<=20), indicating the number of
lines in the input.
This is followed by lines of input text. Each line should accept a maximum of 80 characters.
Output Format
Output the text containing the input lines in reverse order without punctuations except
blanks as illustrated above.
Test your program for the following data and some random data.
Sample Data
Input:
2
Emotions controlled and directed to work, is character.
By Swami Vivekananda.
Output:
Vivekananda Swami By character is work to directed
Input:
1
Do not judge a book by its cover.
output:
cover its by book a judge not Do
and controlled Emotions
~ ring ManipulationsARE GOOD WHEN YOUR THOUGHTS ARE GOOD. AND
Goon. OUR Dey
| Deeds
| Gooa
| Thoughts
| When 1
_ ao . Output: Total n
| You 1
| Yours truly 2
Input: er
IF YOU FAIL TO PLAN YOU ARE PL
ANNING TO FAIL,
Output:
| Word Count‘Output: «
Input a paragraph containing ‘n’ number of
Sete pd an an os wh ce Tone
may be terminated either with a full stop.’ Or a question mark ony Mon ae
character may be ignored. Perform the following operatio ny Soe
(@) Accept the number of sentences. If the number of sentences exceeds the limit,
an appropriate error message must be displayed. .
@ Find the number of words in the whole paragraph,
(0) Display the words in ascending order of their fre ith same
of their frequency. Words wit
frequency may appear in any order. ont
Example 1
Input: Enter number of sentences.
1
Enter sentences.
TO BE OR NOT TO BE.
Output: Total number of words: 6
TO
BE
Example 2
Input: Enter number of sentences.
3
Enter sentences. i
S, IT IS.
THIS IS A STRING PROGRAM. IS THIS EASY? YE’
Output: Total number of words: 11
[Word | Frequency _|
al
viv
sang Manipulations _ 273as
ice’). It is simple letter substitution cipher 4
after it in the alphabets, with the other ane
ROT 13
H/h| fi |
| t 4 t t t
Rr | s/s | t | usa l vw | ww |
get 1 ak
F/f | G/g
X/x | yj)
Waite a program to accept a plain text of length L, where L must be erate fan
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
for(int i= 1,
Hello! How are you?
mein.nextint();
The cipher text is: ‘
eyENC nex To? Se; heluation repres
Example 2:
Input : Encryption helps to secure data
Output: Rapelegvba urycf gb frpher gnon
Example 3
Input: Yes
Output: Invalid Length