 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can read and print 2D array in Java. If you like this video, you can subscribe my YouTube channel. My channel contains 800 plus videos. Now, I am going to demonstrate you how you can read and print 2D array in Java. First of all, I am going to import a package java.util.scanner. So here, util is a package and scanner is the class which is pre-implemented in util package. Now, I am going to define a class whose name is 2D array. Inside this class, I am going to define main method definition. Inside this main function, I am going to declare a 2D array and then I am going to read values from user and those received values will be displayed on output screen. So this way, you can declare a 2D array. If you want to provide rows and columns, so you can write like this. First subscript is containing row size and second subscript is containing column size. Here, I have decided row and column size. If you want to read this value from user, then it is also possible. For that purpose, you have to declare more variables. This input is instance of scanner class which will read values from user. So now, I am going to read values for number of rows and columns. So the message enter row size and column size will be displayed. So first I am going to read row size and then column size. Now I am going to declare memory for this array like this. So now you can see rows and columns are decided by the user. So previously, I have used 3 and 4 constant values which were provided by me. So if you want to create an array or you can say 2D array dynamically with the help of user's input, you can do this like I have demonstrated you in this video till now. Now we have to receive values for this 2D array from user. So again, system.out.print talent. This message will be displayed and elements on output screen. So now we have to read values from user. Here I am going to implement nested loops. First loop is repeating row times and second loop will be repeating column times. And this way values will be received. So these 4 statements line number 14 to 17, these lines are responsible for reading user's input and that the user's input will be stored inside ARR 2D array. So I hope you have understood how we can receive values for 2D array from user in Java. Now I have to display these entered values on output screen in matrix format. System.out.print talent. I am going to display the message you have entered. So this message will be displayed on output screen. Again, I am going to implement 2 loops, one for rows and one for columns. So this statement system.out.print will display array element and tab will be displayed. So here I have used only print. So print talent always print elements from new line. I want to print elements of one row at single line. That's why I have used print instead of print talent. After completion of this J loop, I want to move the cursor on new line. So for that I am simply using system.out.print talent. So it will shift the cursor from current line to next line. So this way from line number 19 to 26, I have implemented the code which will display 2D array in form of matrix on output screen. So this is the complete implementation. I hope you have understood how we can declare 2D array dynamically with the user's input for rows and columns. Then reading values from user and then printing those entered values on output screen. So now I am going to compile and execute the code. So first of all I am going to compile the code. For that purpose, I have to use Java C command. Here I have to use data type at line number 12. So whenever there is an error in your code, Java prints that error in front of you. You can see here line number 12 and error was available at line number 12 in our code. So this way you can identify the errors and you can remove those errors. After removing the error, you have to save the code and again you have to compile the code. Now it is error free. So we can execute this code. It is asking for row and column size. So I am entering 3 as row size and 3 as column size. So now I have to enter 9 elements. You can see the output. Output is displayed in matrix format. In first row 3 elements, in second row 3 elements, in third row 3 elements. So I have entered the size as 3, 3. 3 rows and 3 columns. So that's why 9 elements are displayed in form of a matrix. I hope you have understood how we can work with 2D array in Java. If you like this video, you can subscribe my YouTube channel. Thank you for watching this video.