ttpn

导航

 

题目如题

直接上代码了。

 1 import java.util.Scanner;
 2 
 3 public class test
 4 {
 5     public static void main(String [] args)
 6     {
 7         int m,n,i,j,p;
 8         int array[][]=new int[100][100];
 9         int temp[][]=new int[100][100];
10         Scanner scanner=new Scanner(System.in);
11         System.out.printf("input m,n:");   //m表示矩阵的阶数,n表示的幂数
12         m=scanner.nextInt();
13         n=scanner.nextInt();
14         System.out.printf("input the value of matrix \n");
15         for(i=0;i<m;i++)    //输入矩阵
16         {
17             for(j=0;j<m;j++)
18             {
19                 array[i][j]=scanner.nextInt();
20             }
21         }
22         for(i=0;i<m;i++)
23         {
24             for(j=0;j<m;j++)
25             {
26                for(p=0;p<m;p++)
27                 temp[i][j]+=array[i][p]*array[p][j];
28             }
29         }
30         
31         System.out.printf("the mth power of matrix:\n");
32         for(i=0;i<m;i++)  //输出结果
33         {
34             for(j=0;j<m;j++)
35             {
36                 System.out.printf("%3d",temp[i][j]);
37             }
38             System.out.printf("\n");
39         }
40     }
41 }

 

不解释。

posted on 2017-03-20 22:27  Buzhou  阅读(1831)  评论(0编辑  收藏  举报