Java Basic Practice matrix multiplication for Blue Bridge net questions

Source: Internet
Author: User

------------------------------------------------------------

The first time to feel the importance of good study Qaq

Before doing this problem, please learn: Matrix multiplication (Baidu Encyclopedia)

The power of the matrix is 0: Diagonal is 1 Other values are 0 for example

Results

------------------------------------------------------------

Algorithm

1 ImportJava.util.*;2  Public classMain {3      Public Static voidMain (string[] args) {4Scanner sc =NewScanner (system.in);5         intn =sc.nextint ();6         intm =sc.nextint ();7         Long[] A =New Long[n][n];8         Long[] B =New Long[n][n];9         inti,j;Ten          for(i=0;i<n;i++) One              for(j=0;j<n;j++) AB[I][J]=A[I][J] =Sc.nextlong (); -         if(m==0) -              for(i=0;i<n;i++){ the                  for(j=0;j<n;j++){ -                     if(I==J) System.out.print (1+ ""); -                     ElseSystem.out.print (0+ ""); -                 } + System.out.println (); -             } +         Else if(m==1) A              for(i=0;i<n;i++){ at                  for(j=0;j<n;j++) -System.out.print (a[i][j]+ ""); - System.out.println (); -             } -         Else{ -              for(intz=1;z<m;z++){ in                 Long[] tmp =New Long[n][n]; -                  for(i=0;i<n;i++){ to                      for(j=0;j<n;j++){ +                         LongAdd = 0; -                          for(inty=0;y<n;y++){ theAdd + = a[i][y]*B[y][j]; *                         } $TMP[I][J] =add;Panax Notoginseng                     } -                 } theb =tmp; +             } A              for(i=0;i<n;i++){ the                  for(j=0;j<n;j++) +System.out.print (b[i][j]+ ""); - System.out.println (); $             } $         } -              -     } the}

Java Basic Practice matrix multiplication for Blue Bridge net questions

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.