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: Java Program for Matrix Multiplication

  1. #1
    Junior Member
    Join Date
    May 2022
    Location
    India
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Program for Matrix Multiplication

    I have composed a java program to play out a simple matrix multiplication. For framework duplication the section of the primary grid ought to be equivalent to the line of the subsequent network, then no one but we can perform matrix multiplication.

    package com.example.demo;
     
    public class MatrixMultiplication {
     
            public static void main(String[] args) {
     
                    int a[][] = {{1,2,3},{4,5,6},{7,8,9}};    
     
                    int b[][] = {{1,2,3},{4,5,6},{7,8,9}};    
     
                    int c[][] = new int[3][3];  //rows - 3 and columns -3 
     
                    for (int i = 0; i < 3; i++) {    
     
                           for (int j = 0; j < 3; j++) {    
     
                                     c[i][j] = 0;      
     
                                     for (int k = 0; k < 3; k++) {      
     
                                           c[i][j]+= a[i][k]*b[k][j];      
     
                                     } 
     
                                     System.out.print(c[i][j]+" ");   
                             } 
     
                            System.out.println(); 
                    }    
            }
    }

    What would be the output of this program?
    Last edited by Soham10; May 30th, 2022 at 09:57 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Java Program for Matrix Multiplication

    What would be the output of this program?
    Can you explain what you are asking for?
    Do you have a problem with compiling and executing the code?
    If so, please copy any error messages and paste them here with your questions.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2021
    Location
    Pune
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Arrow Re: Java Program for Matrix Multiplication

    I think he is looking for Output,

    The Output:

    30 36 42 
    66 81 96 
    102 126 150

    I am giving you a source where you can learn more about matrix multiplication: read on Scaler

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Java Program for Matrix Multiplication

    What happens when the code is compiled and executed?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 3
    Last Post: July 18th, 2021, 01:26 PM
  2. Multiplication program
    By PhilThomspon in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 6th, 2012, 01:54 PM
  3. Loop ordering in matrix multiplication
    By murph in forum Loops & Control Statements
    Replies: 3
    Last Post: November 24th, 2011, 03:08 AM
  4. Matrix multiplication problem with different dimensions
    By mightyking in forum Collections and Generics
    Replies: 5
    Last Post: September 25th, 2011, 04:59 PM
  5. Having problem in matrix multiplication....
    By sidhant in forum Java Theory & Questions
    Replies: 5
    Last Post: March 17th, 2011, 01:41 PM

Tags for this Thread