Explanation
This Java program, named array_2d_userdef, is designed to demonstrate how to create, populate, and display a two-dimensional (2D) array whose dimensions and elements are provided by the user at runtime.
The program begins by importing the Scanner class, which is essential for reading user input from the console. Inside the main method, the execution starts. First, it prompts the user to enter the desired number of rows and columns for the 2D array. These values are then used to declare and initialize a 2D integer array.
Next, the program enters a set of nested for loops. The outer loop iterates through each row, and the inner loop iterates through each column within that row. During each iteration, the user is prompted to enter an element for a specific position (e.g., "Enter element at position (0,0): "). The entered value is then stored in the corresponding cell of the 2D array.
After all elements have been entered, another set of nested for loops is used. This time, their purpose is to iterate through the entire 2D array and print each stored element to the console. After printing all elements of a row, System.out.println() is called to move the cursor to the next line, ensuring that the array is displayed in a clear, matrix-like format. Finally, the Scanner object is closed to release system resources.