Results 1 to 2 of 2
  1. #1
    MatthewTurner is offline Member
    Join Date
    May 2015
    Posts
    3
    Rep Power
    0

    Default Adding matrices together

    Hi, I am trying to create a simple programme that adds two defined matrices together,
    ,, if anybody can help me I would really appreciate it, thanks






    public class Question4 {


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

    };
    int [][] numeros2 = {{2,5,8},
    {3,7,9}
    };


    for (int i = 0; i< numeros1.length; i++) {
    for(int j=0; j<[i] numeros2.length; j++ ){
    System.out.println("The added arrays are: " numeros1[i][j]+numeros2[i][j] );

    }
    }

    }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Adding matrices together

    Please wrap your code in code tags for proper formatting. Check your other post for a link.

    You are approaching the problem correctly but I suggest you assign the sum to a new matrix. Then print the new matrix with loops. You should use appropriate print statements to ensure three rows of three columns.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Help with arrays and matrices!
    By chwex in forum New To Java
    Replies: 2
    Last Post: 02-15-2013, 12:34 AM
  2. Help with arrays and matrices!
    By chwex in forum New To Java
    Replies: 3
    Last Post: 02-13-2013, 11:46 AM
  3. Arrays and Matrices
    By Shaeman111 in forum New To Java
    Replies: 2
    Last Post: 11-10-2012, 07:24 AM
  4. how to add columns from Matrices(2D array)
    By John_shok in forum New To Java
    Replies: 7
    Last Post: 10-04-2010, 04:33 PM
  5. How to multiply two matrices
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •