GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Java-Programs/Other-Java-Programs/MatrixMultiplication.java at master · iamarav/Java-Programs

Expand file tree

/

MatrixMultiplication.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
60 lines (47 loc) · 1.67 KB
/

MatrixMultiplication.java

Copy path

File metadata and controls

60 lines (47 loc) · 1.67 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.util.Scanner;
public class MatrixMultiplication {
public static void main(String[] args) {
int lm1=1, hm1=1, lm2=1, hm2=1; //length of matrices 1/2; height of matrices 1/2
//minimum length is 1
Scanner getArrayLength = new Scanner(System.in);
System.out.println("Enter length and height of Array 1: ");
lm1 = getArrayLength.nextInt();
hm1 = getArrayLength.nextInt();
System.out.println("Enter length and height of Array 1: ");
lm2 = getArrayLength.nextInt();
hm2 = getArrayLength.nextInt();
getArrayLength.close();
double array1[][] = new double[lm1][hm1];
double array2[][] = new double[lm2][hm2];
//enter elements in array 1
System.out.println("Enter the elements of first array: ");
Scanner sm = new Scanner(System.in);
for(int x = 0; x <lm1; x++) {
for (int y = 0; y< hm1; y++) {
array1[x][y]= sm.nextDouble();
}
}
//enter elements in array 1
System.out.println("---\nEnter the elements of second array: ");
for(int x = 0; x <lm2; x++) {
for (int y = 0; y< hm2; y++) {
array2[x][y]= sm.nextDouble();
}
}
sm.close(); // closing the scanner
multiplication(array1, array2, lm1, lm2, hm1, hm2);
System.out.println("---\nThe Program has ended.");
}
static double multiplication(double[][] array1, double[][] array2, int lm1, int lm2, int hm1, int hm2) {
double result = 0, temp=0;
for(int i=0;i<lm1;i++) {
for(int j=0; j<hm2; j++) {
temp = array1[i][j]* array2[j][i];
result = result + temp;
System.out.println(array1[i][j] +" * "+ array2[j][i]+ " temp = "+temp+" res = "+result);
}
}
System.out.println("The final result of multiplication is: "+result);
return result;
}
}
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.