DEV Community

Saravanan
Saravanan

Posted on

1 1 1 1 1

Matrix Addition,Matrix Multipliction

1.Matrix Addition:

public static void main(String[] args) {

int[][] a= {{1,2,3}
            {1,2,3},
        {4,5,6}};

int[][] b= {{6,7,8},
        {1,2,3},
        {7,8,9}};
int [][] c=new int[a.length][a[0].length]; 

for(int row=0;row<a.length;row++)
{
    for(int col=0;col<b.length;col++)
    {   
      c[row][col]=a[row][col]+b[row][col];
      System.out.print(c[row][col]+" ");
    }
      System.out.println();
}

}
Enter fullscreen mode Exit fullscreen mode

output:
7 9 11
2 4 6
11 13 15

2.Martix Multipliction:

public static void main(String[] args) {

int[][] a= {{1,2,3},
        {1,2,3},
        {4,5,6}};
int[][] b= {{6,7,8},
        {1,2,3},
        {7,8,9}};
int [][] c=new int[a.length][a[0].length];
for(int row=0;row<a.length;row++)
{
  for(int col=0;col<b.length;col++)
  {
    for(int k = 0;k<b.length;k++)
    {
      c[row][col]=c[row][col]+(a[row][k]*b[k][col]);
    }
    System.out.print(c[row][col]+" ");
  }
     System.out.println();
}

}
Enter fullscreen mode Exit fullscreen mode

output:
29 35 41
29 35 41
71 86 101

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo πŸ“Šβœ¨

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

πŸ‘‹ Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay