Tuesday 27 October 2015

Java Tutorial : Java Array (Add two Matrices)


Click here to watch in Youtube : 
https://www.youtube.com/watch?v=cs6GhaUVRoc&list=UUhwKlOVR041tngjerWxVccw

ArrayDemo.java
/*
 * Addition of 2 matrices in java.
 */

class ArrayDemo
{
    public static void main(String[] args)
    {
        /*
         * Creating two matrices.
         */
        int a[][] =
        {
        { 1, 2, 3 },
        { 4, 5, 6 } };

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

        /*
         * Creating another matrix to store the sum of two matrices
         */
        int c[][] = new int[2][3];

        /*
         * Adding and printing addition of 2 matrices
         */
        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                c[i][j] = a[i][j] + b[i][j];
                System.out.print(c[i][j] + " ");
            }
            System.out.println();
        }

    }

}
Output
2 4 6 
8 10 12
To Download ArrayDemoAddMatricesApp Project Click the below link
https://sites.google.com/site/javaee4321/java/ArrayDemoAddMatricesApp.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment