Page 351 - Cs_withBlue_J_C11_Flipbook
P. 351
OUTPUT:
@ ? ? @
? # # ?
? # # ?
@ ? ? @
21. Write a program in Java to input and store n integers (n > 0) in a single subscripted variable and print each number with its
frequency. The output should contain the number and its frequency in two different columns.
Sample Input:
12 20 4 12 12 20 16 16 14 14 12 20 18 18
Sample Output:
Number Frequency
12 4
14 3
16 2
18 2
20 3
22. Write a program in Java to input elements in a 2D square matrix and check whether it is a Lower Triangular Matrix or not.
Lower Triangular Matrix: A Lower Triangular matrix is a square matrix in which all the entries above the main diagonal are zero.
The entries below or on the main diagonal must be non-zero values.
For example:
Enter the size of the matrix: 4
The Matrix is:
5 0 0 0
3 1 0 0
4 9 4 0
6 8 7 2
The Matrix is Lower Triangular
23. Write a program in Java to enter the natural numbers in a double-dimensional array m × n (where m is the number of rows and n
is the number of columns). Display the new matrix in such a way that the new matrix is the mirror image of the original matrix.
For example:
Sample Input:
8 15 9 18
9 10 7 6
10 8 11 13
12 16 17 19
Sample Output:
18 9 15 8
6 7 10 9
13 11 8 10
19 17 16 12
24. Write a Java program to input two matrices and find the subtraction of their elements in the third matrix. The condition for
finding the subtraction of two matrices in Java is that both the matrices should have the same size.
25. Write a Java program to input elements in an array of size 4 × 3 and print the numbers that are:
a. sum of all the odd numbers in odd positions; and
b. print all the non-boundary elements.
26. Write a program in Java to accept the names and marks in Computer Science of forty students in two single-dimensional arrays
and then print the names and marks of students according to their merit.
349
Arrays 349

