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/MatrixAdd.java at main · PandaWire/Java

Expand file tree

/

MatrixAdd.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
43 lines (43 loc) · 1.29 KB
/

MatrixAdd.java

Copy path

File metadata and controls

43 lines (43 loc) · 1.29 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
// Program to add two matrices in Java -
package matrix;
import java.util.Scanner;
public class MatrixAdd {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int arr1[][] = new int[10][10]; // New 2D array for first matrix
int arr2[][] = new int[10][10]; // New 2D array for second matrix
int sum[][] = new int[10][10]; // New 2D array for sum of the two matrices
int i, j;
// Taking details of first matrix -
System.out.println("Enter details for first matrix: ");
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
System.out.println("Enter number: ");
arr1[i][j] = sc.nextInt();
}
}
// Taking details of second matrix -
System.out.println("Enter details for second matrix: ");
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
System.out.println("Enter number: ");
arr2[i][j] = sc.nextInt();
}
}
System.out.println("Displaying addition of two matrices: ");
// Performing addition of two matrices -
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
sum[i][j] = arr1[i][j] + arr2[i][j];
}
}
// Displaying addition of two matrices -
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
System.out.print(sum[i][j] + " ");
}
System.out.println();
}
}
}
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.