You are here: Home / Topics / Matrix of array example in Java

Matrix of array example in Java

Filed under: Java on 2023-08-23 06:50:50

// print simple matrix of array

public class PrintingInMatrixFormat
{
   public static void main(String[] args)
   {
       int i,j;
       int a[][]=new int[3][3];
       a[0][0]=10;
       a[0][1]=20;
       a[0][2]=30;
       a[1][0]=40;
       a[1][1]=50;
       a[1][2]=60;
       a[2][0]=70;
       a[2][1]=80;
       a[2][2]=90;
       for(i=0;i<3;i++)
       {
           for(j=0;j<3;j++)
           {
               System.out.print(" "+a[i][j]);
           }
           System.out.println("");
       }
   }
}


Output:

10  20  30
40  50  60
70  80  90

 

About Author:
J
Java     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.