Questions List
Browse all explanatory questions of this chapter.
Write one use case of array with function.
What happens if an array is changed inside a function?
Can array elements be modified inside a function?
Write the method declaration to accept an integer array.
What is the advantage of using functions with arrays?
Are arrays passed by value or reference in Java?
Can a function return an array in Java?
How do you pass an array to a method in Java?
What is meant by passing an array to a function in Java?
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
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
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} };
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} };
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} };
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
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} };
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.
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