Chapter Questions

Array in java Questions

Explore chapter-wise explanatory questions and quickly move between related subchapters from a cleaner, more advanced layout.

Questions List

Browse all explanatory questions of this chapter.

23 Total Questions
1

Write one use case of array with function.

Question ID: 8965 Read Details
2

What happens if an array is changed inside a function?

Question ID: 8964 Read Details
3

Can array elements be modified inside a function?

Question ID: 8963 Read Details
4

Write the method declaration to accept an integer array.

Question ID: 8962 Read Details
5

What is the advantage of using functions with arrays?

Question ID: 8961 Read Details
6

Are arrays passed by value or reference in Java?

Question ID: 8960 Read Details
7

Can a function return an array in Java?

Question ID: 8959 Read Details
8

How do you pass an array to a method in Java?

Question ID: 8958 Read Details
9

What is meant by passing an array to a function in Java?

Question ID: 8957 Read Details
10

Write a Java program to sort each row of the following 2D array in ascending order.

Example Input:


9 7 5  
3 1 2  
6 4 8  

Expected Output:


5 7 9  
1 2 3  
4 6 8  

Question ID: 8224 Read Details
11

Write a Java program to multiply two matrices. Ensure that the number of columns in the first matrix is equal to the number of rows in the second matrix.

Given matrices:

Matrix A (2x3):


1  2  3  
4  5  6

Matrix B (3x2):


7  8  
9 10  
11 12

Question ID: 8223 Read Details
12

Write a Java program that prints the diagonal elements of a square 2D array.

Given the following array:


int[][] matrix = {
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 9}
};

Question ID: 8222 Read Details
13

Write a Java program that calculates the sum of each row in a 2D array and prints the result.

Given the following array:


int[][] arr = {
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 9}
};

Question ID: 8221 Read Details
14

Write a Java program to search for a specific element in a 2D array and print its position (row and column index). If the element is not found, print a message indicating that the element was not found.

Given the following 2D array:


int[][] arr = {
    {5, 7, 9},
    {4, 6, 8},
    {1, 2, 3}
};

Question ID: 8220 Read Details
15

Write a Java program that takes a 2D array of size 2x3 and returns its transpose.


1  2  3  
4  5  6

Output:


1  4  
2  5  
3  6

Question ID: 8219 Read Details
16

Write a Java program to calculate and print the sum of all elements in the following 2D array:


int[][] arr = {
    {2, 4, 6},
    {1, 3, 5},
    {7, 8, 9}
};

Question ID: 8218 Read Details
17

Given the following 2D array:


int[][] matrix = {
    {5, 8, 3},
    {4, 9, 7},
    {6, 2, 1}
};

Write a program to display the element at the second row, third column.

Question ID: 8217 Read Details
18

Declare a 2D array of integers in Java with 3 rows and 4 columns. Initialize the array with the following values:


1  2  3  4  
5  6  7  8  
9  10  11  12

Question ID: 8216 Read Details
19

Example of Array Declaration in Different Data Types

Question ID: 7734 Read Details
20

Example of Array Declaration and Initialization

Question ID: 7733 Read Details
21

How do you decide when to use ArrayList and LinkedList?

Question ID: 193 Read Details
22

Why deletion in LinkedList is fast than ArrayList?

Question ID: 192 Read Details
23

What are the advantages of ArrayList over arrays?

Question ID: 191 Read Details