Java Small exercise (matrix multiplication)

Source: Internet
Author: User
/* (Start of Program head Note) * Copyright and version Statement of the program (c) 2011, the Computer College of Yantai University * All rights reserved. * File Name: * Author: Shangpeng * Date of Completion: September 26, 2012 * Version number: 001 * for tasks And the description of the solution method * Input Description: * Problem Description: A two-matrix multiplication program * Program output: * Program Head Comment end/public class Demo01 {/** * * @param args * * * public static void Main (string[] args) {//TODO auto-generated method stub int[][] a={{1,2},{3,4},{5,6}};//define its own matrix int[][]
	b={{1,2,3},{4,5,6}};//itself defines the matrix Printmatrix (A,B);
		
		} static void Printmatrix (int[][] a,int[][] b) {int c[][] = new Int[a.length][b[0].length];
		int x,i,j;
				for (i = 0;i<a.length, i++) {for (j = 0;j<b[0].length;j++) {int temp = 0;
					
				for (x = 0;x<b.length;x++) {temp+=a[i][x]*b[x][j];
				
			} C[i][j] = temp;
		} System.out.println ("Results are after matrix multiplication");
			for (int m = 0;m<a.length;m++) {for (int n = 0;n<b[0].length;n++) {System.out.print (c[m][n]+ "\ t"); } 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.