Home Java Programming Language / Programs / Java Programming Code for Two Dimensional (2D) Array
🚀 Programming Example

Java Programming Code for Two Dimensional (2D) Array

👁 1,581 Views
💻 Practical Program
📘 Step Learning
Two Dimensional Array Program: Following Java Program ask to the user to enter row and column size of the array then ask to the user to enter the array elements, and the program will
No previous program
No next program

💻 Program Code

/* Java Program Example - Two Dimensional Array */

import java.util.Scanner;

public class JavaProgramTwoDarray
{
   public static void main(String args[])
   {
       int row, col, i, j;
       int arr[][] = new int[10][10];
       Scanner scan = new Scanner(System.in);

       System.out.print("Enter Number of Row for Array (max 10) : ");
       row = scan.nextInt();
       System.out.print("Enter Number of Column for Array (max 10) : ");
       col = scan.nextInt();

       System.out.print("Enter " +(row*col)+ " Array Elements : ");
       for(i=0; i<row; i++)
       {
           for(j=0; j<col; j++)
           {
               arr[i][j] = scan.nextInt();
           }
       }

       System.out.print("The Array is :\n");
       for(i=0; i<row; i++)
       {
           for(j=0; j<col; j++)
           {
               System.out.print(arr[i][j]+ "  ");
           }
           System.out.println();
       }
   }
}
                        

🖥 Program Output

Enter Number of Row for Array (max 10) : 3
Enter Number of Column for Array (max 10) : 3
Enter 9 Array Elements : 1
2
3
4
5
6
7
8
9
The Array is :
1  2  3
4  5  6
7  8  9
Press any key to continue . . .
                            

📘 Explanation

Two dimensional array can be made in Java Programming language by using the two loops, the first one is outer loop and the second one is inner loop. Outer loop is responsible for rows and the inner loop is responsible for columns. And both rows and columns combine to make two-dimensional (2D) Arrays.
No previous program
No next program
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.