Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8641055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:25:43+00:00 2026-06-12T11:25:43+00:00

I am having to write this program for school that multiplies a pair of

  • 0

I am having to write this program for school that multiplies a pair of two-dimensional arrays. I keep getting an out of bounds:3 error when I try to run the program.

I have gone over the code many times and can’t for the life of me figure out where the breakdown is happening. I ran a debug and this first breakpoint was at the if statement “if (a[0].length != b.length)” I couldn’t figure out why that was a breakpoint.

Could someone help me?

    public class Multiply {

    public static double[][] Multiply_2D_Arrays(double[][] a, double[][] b)

    { 
        if (a[0].length != b.length) // Check to see if the number of a's colums equals the number of b's rows
        {
            throw new IllegalArgumentException("Matrices don't match: " + a[0].length + " != " + b.length);

        }

        int a_rows = a.length;      // Defines the variable M as the row length of array a
        int b_columns = b[0].length;   // Defines the variable N as the column length of array b
        double[][] c = new double[a_rows][b_columns]; // This means that the dimensions of array c will be the rows of a by the columns of b

        for(int i = 0; i < a.length; i++)
            {
                for(int j = 0; j < b[0].length; j++)
                {
                    for(int k = 0; k < a[0].length; )
                    {

                        c[i][j] += a[i][k] * b[k][j];     //Iterates through each row and column of array a and b and then adding it to the dot point sum

                    }

                }
            }

            return c;      //returns the final new array c

        }

    public static void main(String[] args)

    {
        double[][] array1 = {{4.0, 5.0, 6.0}, {2.0, 1.0, 4.0}, {8.0, 7.0, 6.0}, {1.0, 1.0, 2.0}};
        double[][] array2 = {{5.0, 7.0, 7.0, 8.0}, {8.0, 8.0, 9.0, 2.0}, {10.0, 2.0, 3.0, 1.0}};
        double[][] array3 = Multiply.Multiply_2D_Arrays(array1, array2); //Calls the Multiply_2D_Arrays method

        for(int i = 0; i < array3.length; i++)
        {
            for (int j = 0; j < array3.length; j++)
            {
                System.out.print(array3[i][j] + " ");
            }
        }

        System.out.println();
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:25:45+00:00Added an answer on June 12, 2026 at 11:25 am

    You have missed k++ in
    for(int k = 0; k < a[0].length; )

    Then you have an infinity loop

    Also if you want to print the result as matrix, put System.out.println() inside for loop :

        for(int i = 0; i < array3.length; i++)
        {
            for (int j = 0; j < array3.length; j++)
            {
                System.out.print(array3[i][j] + " ");
            }
            System.out.println();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some issues with this program for school. I am trying to
I am having to write an application that communicates with a third-party program (
I'm having trouble wrapping my head around how to write this query. A hypothetical
For this question, we want to avoid having to write a special query since
Is there a way to write something like this with Mojo::UserAgent ,having the possibility
Having this method: public Boolean isCorrect() { return correct; } I can't write: @XmlType(propOrder
Okay so I am having this problem. I write up a script to be
Okay guys, basically the problem I'm having is this. I've been assigned to write
Trying to write a simple program that prints the Fibonacci sequence. I want to
I'm trying to write a program for school and don't know where to begin.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.