GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Java/Programs/MatrixAdd.java at main · PandaWire/Java Expand file tree/ Copy pathMatrixAdd.javaMore file actions 43 lines (43 loc) · 1.29 KB / Copy pathMatrixAdd.javaFile metadata and controls43 lines (43 loc) · 1.29 KB 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. |