Вы находитесь на странице: 1из 23

More challenges added to "More - Looping the loop" sheet

Keyword Legend
Java keywords We have learned To be Learned

abstract continue for new switch


assert*** default goto* package synchronized
boolean do if private this
break double implements protected throw
byte else import public throws
case enum**** instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp** volatile
const* float native super while
Q No. Problem Description Sample Input Sample Output Cheat Code
2
1 Take two numbers as input from user, calculate their sum, then print it on the screen 7 9
5
2 Take two numbers as input from user, calculate their difference, then print it on the screen 17 -12
5
3 Take two numbers as input from user, calculate their product, print of screen 12 60
16
4 Take two numbers as input from user, calculate quotient of their division, then print it on the screen 3 5
16 use % operator to get the
5 Take two numbers as input from user, calculate the remainder of their division, then print it on the screen 3 1 remainder of division
6 Take number of meters as input from user, convert it to centimeters, then print it on the screen 2 200
7 Take number of kilmeters as input from user, convert it to centimeters, then print it on the screen 2 200000
8 Take number of inches as input from user, convert it to feet, then print it on the screen 5 60
9 Take radius of a circle as input from user, calcualte its perimeter, then print it on the screen 2 12.5664 use float data type
10 Take radius of a circle as input from user, calcualte its area, then print it on the screen 2 50.2654
11 Take side of a square as input from user, calcualte its perimeter, then print it on the screen 6 24
12 Take side of a square as input from user, calcualte its area, then print it on the screen 4 16
4
13 Take length and breadth of a rectangle as input from user, calcualte its perimeter, then print it on the screen 7 22
4
14 Take length and breadth of a rectangle as input from user, calcualte its area, then print it on the screen 7 28
15 Take a number (say 'n') as input from user, calculate sum of first 'n' odd numbers, print it on the screen 4 16
16 Take a number (say 'n') as input from user, calculate the 'nth' odd number, print it on the screen 4 7
17 Take a number (say 'n') as input from user, calculate sum of first 'n' even numbers, print it on the screen 4 20
18 Take a number (say 'n') as input from user, calculate the 'nth' even numbers, print it on the screen 4 8
Take a number (say 'n') as input from user, calculate sum of first 'n' terms of following series, print it on the screen
19 5 7 9 11 13 ....... 4 32
Take a number (say 'n') as input from user, calculate the 'nth' term of following series, print it on the screen
20 5 7 9 11 13 ....... 4 11
Take a number (say 'n') as input from user, calculate sum of first 'n' terms of following series, print it on the screen
21 3 6 12 24 48 ....... 4 45
Take a number (say 'n') as input from user, calculate the 'nth' term of following series, print it on the screen
22 3 6 12 24 48....... 4 24
Take a number (say 'n') as input from user, calculate sum of first 'n' terms of following series, print it on the screen
23 3 7 11 15 19 23 ....... 4 36
Take a number (say 'n') as input from user, calculate the 'nth' term of following series, print it on the screen
24 3 7 11 15 19 23....... 4 15
48 219
25 Take two number as input from the user, swap the values of these variables, print it on the screen 219 48
Write a program to count minimum number of notes required for a given amount(valid notes are 2000,500,100,
26 50, 20, 10, 5, 1). 4553 7
1 Year Assume
1 Month 365 days in a year.
27 Write a program to take number of days as input and convert it into years, months and weeks 400 5 Days 30 days in a month
60
28 Write a program to take two angles of a triangle as input and find the third angle 90 30 Recall rules of trigonometry
29 Write a program to enter base and height of a triangle and find its area
30 Write a program to calculate area of an equilateral triangle
31 Write a program to enter marks of five subjects and calculate total, average and percentage
32 Write a program to enter Principal, Time, Rate, calculate & print Simple Interest
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Q No. Problem Description Sample Input Sample Output Cheat Code
2
51 Take 2 numbers as input from user, print the largest number on the screen 6 6
3
7
52 Take 3 numbers as input from user, print the largest number on the screen 2 7
53 Take the age of the user as input, print if the user is a teenager 15 Teenager: Beware of my Tantrums
4 Lets get Even

54 Take a number as an input, print if the number is odd or even 9 Odd one out
2004 Yay!!! One extra day to live your life.

55 Take the year as an input, print on the screen if it is a Leap year 2007 Get paid for the whole month while working for 28 days only :-)
3 Infants: Soo Cute

15 Teenager: Beware of my Tantrums

45 Others: Damnn!!!!!
Take the age of the user as input, print if the user is an infant (Age 0-5) or teenager
56 (Age 13-19), a senior citizen (>60), or Others 67 Senior Citizen: Earn extra interest on fixed deposits
Write a program to create a basic calculator.
Provide a menu with 4 options to the user and let the user choose one of the options[1-
4].
After the user has chosen the option take 2 more numbers as input from the user.
Perform the operation that user has chosen in first step.

1. Add
2. Subtract 1
3. Multiply 7
57 4. Divide 8 15
Take the price of an item as input from the user. Also take input the rate of GST on the 100
58 item. print the final price of the item by adding GST amount to the price. 15 115
5 Positive

0 Zero

59 Write a program to check whether a number is negative, positive or zero. -8 Negative


60 Yes

60 Write a program to check whether a number is divisible by 5 and 11 or not. 110 No


use data type char.

a English e.g.

61 Write a program to check whether a character is a letter of English alphabet or not. 5 Not English char sampleChar = 'a';
e Vowel

62 Write a program to input any letter and check whether it is a vowel or consonant. m Consonant
d
English
&
Special Character
Write a program to input any character and check whether it is an English letter, digit or 5
63 special character. Digit
a Lower Case

64 Write a program to check if a user input character is upper case of lower case letter D Upper Case
Take code price and selling price of an item as input. Write a program to calculate profit
65 or loss.
4 Thursday
Write a program to input week number and print week day (Week starts on Monday and
66 ends on Sunday). 7 Sunday
67 Write a program to input month number and print number of days in that month. 5 31
30
60 It is a triangle
90

20
40 It is not a triangle
68 Write a program to input angles of a triangle and check whether triangle is valid or not. 60
3
3 equilateral
3

3
3 isosceles
6

4
Write a program to check whether the triangle is equilateral, isosceles or scalene 5 scalene
69 triangle. 6
Write a program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer.
Calculate percentage and grade according to following:
Percentage >= 90% : Grade A
Percentage >= 80% : Grade B
Percentage >= 70% : Grade C
Percentage >= 60% : Grade D
Percentage >= 40% : Grade E
70 Percentage < 40% : Grade F
Write a program to input basic salary of an employee and calculate its Gross salary
according to following:
Basic Salary <= 10000 : HRA = 20%, DA = 80%
Basic Salary <= 20000 : HRA = 25%, DA = 90%
71 Basic Salary > 20000 : HRA = 30%, DA = 95%
Write a program to input electricity unit charges and calculate total electricity bill
according to the given condition:
For first 50 units Rs. 0.50/unit
For next 100 units Rs. 0.75/unit
For next 100 units Rs. 1.20/unit
For unit above 250 Rs. 1.50/unit
72 An additional surcharge of 20% is added to the bill
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
Q No. Problem Description Sample Input Sample Output Cheat Code
101 Write a program to print day of week name using switch case.
102 Write a program print total number of days in a month using switch case.
103 Write a program to check whether an alphabet is vowel or consonant using switch case.
104 Write a program to find maximum between two numbers using switch case.
105 Write a program to check whether a number is even or odd using switch case.
106 Write a program to create Simple Calculator using switch case
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
Q No. Problem Description Sample Input Sample Output Cheat Code
151 Write a program to print all natural numbers from 1 to n. 4 1, 2, 3, 4,
152 Write a program to print all natural numbers in reverse (from n to 1). 4 4, 3, 2, 1,
153 Write a program to print all alphabets from a to z. a, b, c, d, ....... z,
154 Write a program to print all even numbers between 1 to 100. 2, 4, 6, 8, ....98, 100,
155 Write a program to print all odd number between 1 to 100. 1, 3, 5, 7, .....97, 99
156 Write a program to find sum of all natural numbers between 1 to n. 4 10
157 Write a program to find sum of all even numbers between 1 to n. 6 12 2+4+6
158 Write a program to find sum of all odd numbers between 1 to n. 6 9 1+3+5
159 Write a program to print multiplication table of any number. 5 5, 10, 15, 20, 25, 30, 35, 40, 45, 50,
160 Write a program to count number of digits in any number. 6482 4 remember remainder
161 Write a program to find first and last digit of any number. 6482 6, 2,
162 Write a program to find sum of first and last digit of any number. 6482 8
163 Write a program to swap first and last digits of any number. 6482 2486
164 Write a program to calculate sum of digits of any number. 6482 20
165 Write a program to calculate product of digits of any number. 6482 384
Write a program to enter any number, then store its reverse in another variable and
166 then print it 6482 2846
34654 Not Pallindrome

2112 Pallindrome
Write a program to enter any number and check whether the number is palindrome or Pallindrome is a number which is same even if you reverse the
167 not. 989 Pallindrome digits e.g. 2332, 45654, 121, 2 etc. are all pallindrome numbers
32345 2-1, 3-2, 4-1, 5-1

213 1-1, 2-1, 3-1

168 Write a program to find frequency of each digit in a given integer. 456455 4-2, 5-3, 6-1
345 Three Four Five

169 Write a program to enter any number and print it in words. 76578 Seven Six Five Seven Eight
34 81

170 Write a program to find power of any number 25 32


171 Write a program to enter any number and print all factors of the number.
4 24

172 Write a program to enter any number and calculate its factorial. 5 120
173 Write a program to print Fibonacci series up to n terms. 8 0, 1, 1, 2, 3, 5, 8, 13 0, 1, 1, 2, 3, 5, 8, 13 is a fibonacci series.
4 No

3 Yes

174 Write a program to check whether a number is Prime number or not. 11 Yes
A prime number is a natural number greater than 1 that has no
175 Write a program to print all Prime numbers between 1 to n. 11 2, 3, 5, 7, 11 positive divisors other than 1 and itself.
176 Write a program to find sum of all prime numbers between 1 to n. 11 28
Prime factors are all the divisors of a number that are prime
numbers.

e.g.

8 1, 2, prime factors of 8 are 1,2,


prime factors of 15 are 1,3,5
15 1, 3, 5, prime factors of 20 are 1,2,5

177 Write a program to enter any number and print its prime factors. 20 1, 2, 5,
An Armstrong number is a number that is the sum of its own
digits each raised to the power of the number of digits in that
number

e.g

An Armstrong number of 3 digits is an integer such that the sum


of the cubes of its digits is equal to the number itself.
320 Not an armstrong number
i.e 371 is an Armstrong number since (3*3*3) + (7*7*7) + (1*1*1)
178 Write a program to check whether a number is Armstrong number or not. 371 Armstrong number = 371
179 Write a program to print all Armstrong numbers between 1 to n.
Proper divisors of a number are all the divisors of the given
number except the given number itself

e.g.
8 1, 2, 4, divisors of number 6 are 1,2,3,6
BUT
180 Write a program to print all proper divisors of a number provided by the user 6 1, 2, 3, proper divisors of 6 are 1,2,3 only.
A perfect number is a positive integer that is equal to the sum of
its proper positive divisors

e.g.

6 Perfect number proper divisor of 6 are 1, 2, 3, and


1+2+3 = 6
181 Write a program to check whether a number is Perfect number or not. 8 Not a perfect number therefore 6 is a perfect number
182 Write a program to print all Perfect numbers between 1 to n.
Strong numbers are the numbers whose sum of factorial of
digits is equal to the original number itself

e.g.
120 Strong number
145 is a strong number because
183 Write a program to check whether a number is Strong number or not. 145 Not a strong number 1! + 4! + 5! => 1 + 24 + 120 => 145
184 Write a program to print all Strong numbers between 1 to n.
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
Q No. Problem Description Sample Input Sample Output Cheat Code
Write a program that takes 5 integers as input from the user and /* Syntax to declare an int array of size 5*/
301 Print the first number entered by the user 14 5 7 12 32 14 int [] intArray = new int[5];
Write a program that takes 5 integers as input from the user and
302 Print the last number entered by the user 14 5 7 12 32 32
Write a program that takes 5 integers as input from the user and
303 Print sum total of all the numbers 14 5 7 12 32 70
Write a program that takes 5 integers as input from the user and
304 Print average of all the number 14 5 7 12 32 14
Write a program that takes 5 integers as input from the user and
305 Print Max of all the numbers 14 5 7 12 32 32
Write a program that takes 5 integers as input from the user and
306 Print Min of all the numbers 14 5 7 12 32 5
Write a program that takes 5 integers as input from the user and
307 Swap the values of 1st and the last numbers entered by the user and print all the numbers 14 5 7 12 32 32, 5, 7, 12, 14,
Write a program that takes 'n' integers as input from the user 7 86 /*Syntax to declare an int array of user provided size*/
and If the total number of numbers entered by the user is odd 3 14 5 86 12 32 19 int arraySize;
then Print the number at the middle of the list arraySize = userInput.nextInt();
If the total number of numbers entered by the user is even 4 51
308 then Print the average of 2 numbers that are at the middle of the list 5 31 71 42 int [] intArray = new int[arraySize];
Write a program that takes 'n' integers as input from the user
and Print the Kth number from the array 7
Hint: 3 14 5 7 12 32 19
309 Take K as input from the user 6 32
Write a program that takes 'n' integers as input from the user 7 19 14 5 7 12 32 3
310 and Swap the values of 1st and the last element of the array and then print all the numbers 3 14 5 7 12 32 19
7 3 14 5 7 32 19
Write a program that takes 'n' integers as input from the user 3 14 5 7 12 32 19
311 and Remove the K'th element from the array and then print the numbers in the array 5
7 3 14 5 7 25 32 19
Write a program that takes 'n' integers as input from the user 3 14 5 7 12 32 19
312 and insert a new number at Kth location in the array and then print the numbers 5 25
Write a program that takes 'n' integers as input from the user 7 19, 32, 12, 7, 5, 14, 3
313 and Reverse the order of numbers in the array 3 14 5 7 12 32 19
Write a program that takes 'n' integers as input from the user 5 Pallindrome
and finds out if the order of numbers in array is pallindrome 12 45 87 45 12
e.g.
if input numbers are 44 56 56 44 then the array is in pallindrome order 5 Not Pallindrome
314 if input numbers are 44 53 156 44 then the array is not in pallindrome order 89 34 23 54 11
315 Write a program to copy all numbers from an array to another array.
316 Write a program to count total number of negative numbers in an array.
317 Write a program to count total number of even and odd numbers in an array on integers
318 Write a program to put even and odd numbers of array in two separate array.
319 Write a program to merge two array to third array.
Write a program to search a number in an array and print the index of the first occurance of the number
320 in the array
321 Write a program to print all unique numbers in the array.
322 Write a program to count total number of duplicate numbers in an array.
323 Write a program to delete all duplicate numbers from an array.
324 Write a program to count frequency of each element in an array.
Write a program to left rotate an array by 'K' position where 'K' is taken as an input from user. If 'K' is
325 negative then right rotate the array
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
Q No. Problem Description Function Parameters Sample Output Cheat Code
write a function in Java to print following pattern ****
****
Note: Number of rows and columns shall be the input parameters ****
to the function ****
****
Rectangle

****
****
****
****
451 **** 5,4
write a function in Java to print following pattern ****
* *
Note: Number of rows and columns shall be the input parameters * *
to the function * *
****
Hollow Rectangle

****
* *
* *
* *
452 **** 5,4
write a function in Java to print following pattern *****
*****
Note: Number of rows and columns shall be the input parameters *****
to the function *****
*****
Parallelogram

*****
*****
*****
*****
453 ***** 5,5
write a function in Java to print following pattern *****
* *
Note: Number of rows and columns shall be the input parameters * *
to the function * *
*****
Hollow Parallelogram

*****
* *
* *
* *
454 ***** 5,5
write a function in Java to print following pattern *******
*******
Note: Number of rows and columns shall be the input parameters *******
to the function *******
*******
Mirrored Parallelogram

*******
*******
*******
*******
455 ******* 5,7
write a function in Java to print following pattern *******
* *
Note: Number of rows and columns shall be the input parameters * *
to the function * *
*******
Hollow mirrored Parallelogram

*******
* *
* *
* *
456 ******* 5,7
write a function in Java to print following pattern *
**
Note: Only number of rows shall be the input parameter to the ***
function

Right triangle

*
**
***
****
457 ***** 3
write a function in Java to print following pattern *
**
Note: Only number of rows shall be the input parameter to the * *
function * *
*****
Hollow right triangle

*
**
* *
* *
458 ***** 5
write a function in Java to print following pattern *
**
Note: Only number of rows shall be the input parameter to the ***
function ****

Mirrored right triangle

*
**
***
****
459 ***** 4
write a function in Java to print following pattern *
**
Note: Only number of rows shall be the input parameter to the * *
function * *
*****
Hollow mirrored right triangle

*
**
* *
* *
460 ***** 5
write a function in Java to print following pattern ***
**
Note: Only number of rows shall be the input parameter to the *
function

Inverted right triangle

*****
****
***
**
461 * 3
write a function in Java to print following pattern *****
* *
Note: Only number of rows shall be the input parameter to the * *
function **
*
Hollow inverted right triangle

*****
* *
* *
**
462 * 5
write a function in Java to print following pattern ***
**
Note: Only number of rows shall be the input parameter to the *
function

Inverted mirrored right triangle

*****
****
***
**
463 * 3
write a function in Java to print following pattern *****
* *
Note: Only number of rows shall be the input parameter to the * *
function **
*
Hollow inverted mirrored right triangle

*****
* *
* *
**
464 * 5
write a function in Java to print following pattern *
***
Note: Only number of rows shall be the input parameter to the *****
function *******

Pyramid (Equilateral triangle)


*
***
*****
*******
465 ********* 4
write a function in Java to print following pattern *
* *
Note: Only number of rows shall be the input parameter to the * *
function *******

Hollow Pyramid

*
* *
* *
* *
466 ********* 4
write a function in Java to print following pattern *********
*******
Note: Only number of rows shall be the input parameter to the *****
function ***
*
Inverted Pyramid

*********
*******
*****
***
467 * 5
write a function in Java to print following pattern *********
* *
Note: Only number of rows shall be the input parameter to the * *
function * *
*
Hollow inverted pyramid

*********
* *
* *
* *
468 * 5
write a function in Java to print following pattern *
**
Note: Only number of columns will be the input parameter to the ***
function ****
***
Half diamond **
*
*
**
***
****
*****
****
***
**
469 * 4
write a function in Java to print following pattern *
**
Note: Only number of columns will be the input parameter to the ***
function ****
*****
Mirrored half diamond ****
***
* **
** *
***
****
*****
****
***
**
470 * 5
write a function in Java to print following pattern *
***
Note: Only odd number of rows will be the input parameter to the *****
function. If the number of rows is even then print an error and *******
return false else return true. *****
***
Diamond *

*
***
*****
*******
*********
*******
*****
***
471 * 7
write a function in Java to print following pattern **********
**** ****
Note: Only odd number of rows will be the input parameter to the *** ***
function. If the number of rows is even then print an error and ** **
return false else return true. * *
** **
Hollow diamond *** ***
**** ****
********** **********
**** ****
*** ***
** **
* *
** **
*** ***
**** ****
472 ********** 9
write a function in Java to print following pattern ****
***
Note: Only odd number of rows will be the input parameter to the **
function. If the number of rows is even then print an error and *
return false else return true. **
***
Right Arrow ****

*****
****
***
**
*
**
***
****
473 ***** 7
write a function in Java to print following pattern ***
**
Note: Only odd number of rows will be the input parameter to the *
function. If the number of rows is even then print an error and **
return false else return true. ***

Left arrow

*****
****
***
**
*
**
***
****
474 ***** 3
write a function in Java to print following pattern +
+
Note: Only odd number of rows will be the input parameter to the +
function. If the number of rows is even then print an error and +++++++
return false else return true. +
+
Plus +

+
+
+
+
+++++++++
+
+
+
475 + 7
write a function in Java to print following pattern * *
* *
Note: Only odd number of rows will be the input parameter to the * *
function. If the number of rows is even then print an error and *
return false else return true. * *
* *
X pattern * *

* *
* *
* *
* *
*
* *
* *
* *
476 * * 7
write a function in Java to print following pattern 1111
2222
Note: Number of rows and columns shall be the input parameters 3333
to the function

11111
22222
33333
44444
477 55555 3,4
write a function in Java to print following pattern 123
123
Note: Number of rows and columns shall be the input parameters 123
to the function 123

12345
12345
12345
12345
478 12345 4,3
write a function in Java to print following pattern 123
321
Note: Number of rows and columns shall be the input parameters 123
to the function 321

12345
54321
12345
54321
479 12345 4,3
write a function in Java to print following pattern 12345
23451
Note: Only number of rows shall be the input parameter to the 34512
function 45123

12345
23451
34512
45123
480 51234 4,5
write a function in Java to print following pattern 111
000
Note: Number of rows and columns shall be the input parameters 111
to the function 000
111
11111
00000
11111
00000
481 11111 5,3
write a function in Java to print following pattern 10101
10101
Note: Number of rows and columns shall be the input parameters 10101
to the function 10101

10101
10101
10101
482 10101 4,5
write a function in Java to print following pattern 101010
010101
Note: Number of rows and columns shall be the input parameters 101010
to the function 010101
101010
10101
01010
10101
01010
483 10101 5,5
write a function in Java to print following pattern 11111
10001
Note: Number of rows and columns shall be the input parameters 10001
to the function 11111

11111
10001
10001
10001
484 11111 4,5
write a function in Java to print following pattern 11111
11011
Note: Odd number of rows and columns shall be the input 11111
parameters to the function. If the number of rows or columns is
even then print an error and return false otherwise print the
pattern and return true.

11111
11111
11011
11111
485 11111 3,5
write a function in Java to print following pattern 101
101
Note: Odd number of rows and columns shall be the input 000
parameters to the function. If the number of rows or columns is 101
even then print an error and return false otherwise print the 101
pattern and return true.

11011
11011
00000
11011
486 11011 5,3
write a function in Java to print following pattern 101
010
Note: Odd number of rows shall be the input parameter to the 101
function. If the number of rows is even then print an error and
return false otherwise print the pattern and return true.

10001
01010
00100
01010
487 10001 3
write a function in Java to print following pattern 0110
1001
Note: number of rows and columns shall be the input parameters 1001
to the function. 1001
0110
01110
10001
10001
10001
488 01110 5,4
1 2 3 4 5 /*
6 7 8 9 10 Following statement will print the value of an
11 12 13 14 15 integer on the screen
16 17 18 19 20 and also
it will always occupy a width of 5 characters on
the screen.
and also
write a function in Java to print following pattern keep the value right justified within those 5
spaces.
Note: number of rows and columns shall be the input parameters */
to the function.
System.out.printf("%5d", sampleInt);
1 2 3 4 5
6 7 8 9 10 //e.g. if the value of sampleInt = 12
11 12 13 14 15 //then the output of above statement will be as
16 17 18 19 20 below
489 21 22 23 24 25 4,5 12
write a function in Java to print following pattern 1234
2344
Note: number of rows shall be the input parameter to the 3444
function. 4444

12345
23455
34555
45555
490 55555 4
write a function in Java to print following pattern 666666
655555
Note: Only number of rows shall be the input parameter to the 654444
function. 654333
654322
55555 654321
54444
54333
54322
491 54321 6
write a function in Java to print following pattern 3 3 3 3 3
3 2 2 2 3
Note: Odd number of rows shall be the input parameter to the 3 2 1 2 3
function. If the number of rows even then print an error and 3 2 2 2 3
return false otherwise print the pattern and return true. 3 3 3 3 3

5 5 5 5 5 5 5 5 5
5 4 4 4 4 4 4 4 5
5 4 3 3 3 3 3 4 5
5 4 3 2 2 2 3 4 5
5 4 3 2 1 2 3 4 5
5 4 3 2 2 2 3 4 5
5 4 3 3 3 3 3 4 5
5 4 4 4 4 4 4 4 5
492 5 5 5 5 5 5 5 5 5 5
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

1
22
333
4444
493 55555
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

55555
4444
333
22
494 1
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

11111
2222
333
44
495 5
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

5
44
333
2222
496 11111
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

1
12
123
1234
497 12345
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

12345
1234
123
12
498 1
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

1
21
321
4321
499 54321
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

54321
4321
321
21
500 1
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

5
54
543
5432
501 54321
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

54321
5432
543
54
502 5
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

5
45
345
2345
503 12345
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

12345
2345
345
45
504 5
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

1
23
345
4567
505 56789
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

56789
4567
345
23
506 1
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

13579
3579
579
79
507 9
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function


1
10
101
1010
508 10101
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function


1
00
111
0000
509 11111
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function


1
01
010
1010
510 10101
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function


1
11
101
1001
511 11111
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

1
123
12345
1234567
512 123456789
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

1
24
135
2468
513 13579
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

1
131
13531
1357531
514 135797531
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

2
242
24642
515 2468642
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

1
121
12321
1234321
516 123454321
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

1
32
4543
567654
517 67898765
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

1
2 3
4 5 6
7 8 9 10
518 11 12 13 14 15
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

1
21
123
4321
519 12345
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

1
2 3
4 5 6 7
8 9 1 2 3 4 5 6
520 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

1 1
12 21
123 321
1234 4321
1234554321
521
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

1
2 6
3 7 10
4 8 11 13
522 5 9 12 14 15
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

1
2 4
7 11 16
22 29 37 46
523 56 67 79 92 106
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

1
3 2
4 5 6
10 9 8 7
524 11 12 13 14 15
write a function in Java to print following pattern

Note: Number of rows shall be the input parameter to the function

1
22
333
2222
525 11111
write a function in Java to print following pattern

Note: Only odd number of rows will be the input parameter to the
function. If the number of rows is even then print an error and
return false otherwise print the pattern and return true.

1
12
123
1234
12345
1234
123
12
526 1
write a function in Java to print following pattern

Note: Only odd number of rows will be the input parameter to the
function. If the number of rows is even then print an error and
return false otherwise print the pattern and return true.

1
123
12345
1234567
123456789
1234567
12345
123
527 1
write a function in Java to print following pattern

Note: Only odd number of rows will be the input parameter to the
function. If the number of rows is even then print an error and
return false otherwise print the pattern and return true.

1
121
12321
1234321
123454321
1234321
12321
121
528 1
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
Q No. Problem Description Input Parameter Return Value Cheat Code
Write a function to check whether two matrices are equal or not. If equal 5 4 3 5 4 3 true
return true otherwise return false. 6 8 2 6 8 2
Two matrices are equal when they have same number of rows and cols and each 4 5 6 4 5 6
element of one matrix is equal to the corresponding element of second //Function declarion shall look like this
matrix.
boolean isEqual( int [][] firstMatrix, int[][]
Note: secondMatrix)
1. Function takes 2 input parameters {
2. Both the parameters are integer matrices i.e. 2-dimensional arrays //Your code goes here
601 3. The function shall return a boolean value }
Write a function to calculate sum of main diagonal elements of a matrix and 3 4 5 2 15
return the sum from the function 4 5 2 9
8 3 7 2
e.g.: There are 3 example matrices shown below with their main diagonal
elements marked red

3 4 5 2 5 4 3 4 3
4 5 2 9 6 8 2 9 2
8 3 7 2 7 4
3 8 4 2 3 5

Note:
1. Function takes 1 matrix as input parameter i.e. a 2-dimensional arrays
2. The function shall return an integer value which should be the sum of
602 main diagonal elements of the input matrix
Write a function to calculate sum of minor diagonal elements of a matrix and 3 4 5 2 7
return the sum from the function 4 5 2 9
8 3 7 2
e.g.: There are 3 example matrices shown below with their minor diagonal
elements marked red

3 4 5 2 5 4 3 4 3
4 5 2 9 6 8 2 9 2
8 3 7 2 7 4
3 8 4 2 3 5

Note:
1. Function takes 1 matrix as input parameter i.e. a 2-dimensional arrays
2. The function shall return an integer value which should be the sum of
603 minor diagonal elements of the input matrix
Write a function to calculate the sum of each row of a matrix and return 5 4 3 11 16
them as an integer array from the function 6 8 2
604
Write a function to calculate the sum of each col of a matrix and return 5 4 3 11 12 5
them as an integer array from the function 6 8 2

5 4 3
605 6 8 2
3 4 5 2 2 4 5 3
4 5 2 9 4 2 5 9
Write a function to swap diagonals of a square matrix i.e. main diagonal 8 3 7 2 8 7 3 2
606 will become minor and minor diagonal will become main. 3 8 4 2 2 8 4 3
Write a function to return sum of upper triangular element of a square 5 4 3 22
matrix 6 8 2
3 1 0
e.g. elements marked red below are the upper triangular elements of a square
matrix

3 4 5 2
4 5 2 9
8 3 7 2
607 3 8 4 2
Write a function to return sum of lower triangular element of a square 5 4 3 23
matrix 6 8 2
3 1 0
e.g. elements marked red below are the lower triangular elements of a square
matrix

3 4 5 2
4 5 2 9
8 3 7 2
608 3 8 4 2
Write a function to check if the matrix given as input parameter is an 1 0 0 0 true
Identity matrix or not. 0 1 0 0
The identity matrix of size n is the n n square matrix with 1 on the main 0 0 1 0
diagonal and zeros elsewhere. The function shall retun true if the input 0 0 0 1
matrix is an identity matrix false otherwise. Function shall return false if
the matrix is not a square matrix.

e.g. following is an identity matrix of size 3

1 0 0
0 1 0
609 0 0 1
Write a function to add two matrices 5 4 3 1 2 1 6 6 4 //Function declarion shall look like this
6 5 2 3 4 6 9 9 8
Note: 4 5 6 4 2 1 8 7 7 int[][] addMatrices( int [][] firstMatrix, int[][]
1. Function takes 2 input parameters secondMatrix)
2. Both the parameters are integer matrices i.e. 2-dimensional arrays {
3. The function shall return a 2-dimensional array that contains the //Your code goes here
610 addition of the matrices received as input parameters in the functions }
Write a function to subtract two matrices 5 4 3 1 2 1 4 2 2
6 5 2 3 4 6 3 1 -4
Note: 4 5 6 4 2 1 0 3 5
1. Function takes 2 input parameters
2. Both the parameters are integer matrices i.e. 2-dimensional arrays
3. The function shall return a 2-dimensional array that contains the
611 difference of the matrices received as input parameters in the functions
Write a function to perform Scalar multiplication of a matrix. 5 4 3 3 15 12 9
Scalar multiplication of matrix M and number A is calculated by multiplying 6 8 2 18 24 6
each element of the M by A. 4 5 6 , 12 15 18

Note:
1. Function takes 2 input parameters
2. First parameter in an integer matrix and second parameter is an integer
number
3. The function shall return a 2-dimensional array that contains the scalar
612 multiplication i.e (number x matrix)
Write a function to multiply two matrices and return the resultant matrix. 1 4 3 2 3 18 25
if A is an n m matrix and B is an m p matrix, 3 1 2, 1 4 15 17
their matrix product AB is an n p matrix, 4 2
in which the m entries across a row of A are multiplied with the m entries
613 down a columns of B and summed to produce an entry of matrix AB
614
615
Q No. Problem Description Input Parameter Return Value Cheat Code
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
Coming soon...

Вам также может понравиться