Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Need help populating two matrices with method

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Need help populating two matrices with method

    This is the method public void populateMatrices(int [][]mat1, int [][]mat2). I know how to do it for one matrix, but what do we do for the additional matrix? Here is the code I have so far.
    for (int row =0; row<mat1.length;row++){
    for (int column = 0; column<mat1[row].length;column++){
    mat1[row][column]=1 + (int)(Math.random()*5);
    Any help would be appreciated.
    Thanks


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Need help populating two matrices with method

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly per the above link.

    For the second matrix, simply add the line:

    mat2[row][column]=1 + (int)(Math.random()*5);

    to the nested for() loop body, modifying as needed the formula for the mat2 values.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    rhelping (September 9th, 2014)

  4. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help populating two matrices with method

    thanks

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Need help populating two matrices with method

    You're welcome.

Similar Threads

  1. Problem with Populating a List
    By steveby63 in forum Object Oriented Programming
    Replies: 2
    Last Post: July 18th, 2014, 10:24 AM
  2. Populating a LinkedList in java
    By pyler in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 18th, 2014, 01:14 PM
  3. ILL CONDITION MATRICES
    By soso84 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 27th, 2013, 09:54 AM
  4. Java program to do Matrix operation
    By saladfingers73 in forum Collections and Generics
    Replies: 5
    Last Post: March 7th, 2012, 09:17 AM
  5. Populating a JTable
    By crism85 in forum AWT / Java Swing
    Replies: 0
    Last Post: February 20th, 2010, 01:57 PM