top of page
Writer's pictureKaran Chaudhary

2D ARRAY (Two-Dimensional) in JAVA

A two-dimensional array in Java is an array that contains elements in a grid-like format. Each element in the array can be thought of as a row and a column. This type of array is commonly used in many programming languages to store and manipulate data in a structured manner.


To create a two-dimensional array in Java, you can use the following syntax:





In this example, rows represents the number of rows in the array and columns represents the number of columns in the array. You can then access elements in the array by specifying the row and column indices, such as array[i][j] where i is the row index and j is the column index.


Here's an example of a two-dimensional array in Java that stores the marks of a group of students in a class:



In this example, the two-dimensional array marks has 3 rows and 4 columns, representing the marks of 3 students in 4 subjects.


You can also use nested for loops to iterate through the elements of a two-dimensional array:




In this example, the outer loop iterates through the rows of the two-dimensional array and the inner loop iterates through the columns of each row.


Two-dimensional arrays in Java are a powerful tool for storing and manipulating data in a structured manner. Whether you're working with a table of values, a grid of cells, or a matrix of numbers, a two-dimensional array can help you organize and manipulate your data more efficiently.

11 views0 comments

Recent Posts

See All

Comments


bottom of page