Java Matrix Multiplication

Source: Internet
Author: User
Import Java. io. bufferedreader; import Java. io. inputstreamreader; import Java. util. extends; public class main {public static void main (string [] ARGs) {Using SC = new using (New bufferedreader (New inputstreamreader (system. in); string R; system. out. println ("Enter the rows and columns of matrix A (columns are separated by spaces):"); int R1 = SC. nextint (); int r2 = SC. nextint (); int A [] [] = new int [R1] [R2]; system. out. println ("Enter the elements of matrix A:"); For (INT I = 0; I <R1; I ++) {for (Int J = 0; j <R2; j ++) {A [I] [J] = SC. nextint ();} SC. nextline ();} system. out. println ("Enter the rows and columns of matrix B (columns are separated by spaces):"); int R3 = SC. nextint (); int r4 = SC. nextint (); int B [] [] = new int [R3] [R4]; int C [] [] = new int [R1] [R4]; system. out. println ("Enter the elements of matrix B:"); For (INT I = 0; I <R3; I ++) {for (Int J = 0; j <R4; j ++) {B [I] [J] = SC. nextint ();} SC. nextline () ;}for (INT I = 0; I <R1; I ++) {for (Int J = 0; j <R4; j ++) {for (int K = 0; k <R3; k ++) {c [I] [J] = C [I] [J] + A [I] [k] * B [k] [J] ;}} system. out. println ("matrix C:"); For (INT I = 0; I <R1; I ++) {for (Int J = 0; j <R4; j ++) {system. out. print (C [I] [J] + "");} system. out. println ();}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.