matrix addition

matrix addition

hai

View Answers

January 20, 2011 at 11:34 AM

Hi,

Try this:

import java.util.*;
class MatrixAddition{

    public static void main(String[] args){
     Scanner input = new Scanner(System.in);
    int[][] A = new int[3][3];
int[][] B = new int[3][3];
int[][] C = new int[3][3];
System.out.println("Enter elements for matrix A : ");
for (int i=0 ; i < A.length ; i++)
for  (int j=0 ; j < A[i].length ; j++){
A[i][j] = input.nextInt();
}
System.out.println("Enter elements for matrix B : ");
for (int i=0 ; i < B.length ; i++)
for  (int j=0 ; j < B[i].length ; j++){
B[i][j] = input.nextInt();
}
System.out.println("Matrix A: ");
        for (int i=0 ; i < A.length ; i++){
            System.out.println();
            for  (int j=0 ; j < A[i].length ; j++){
                System.out.print(A[i][j]+" ");
                  }
        }
System.out.println();
System.out.println();
System.out.println("Matrix B: ");
        for (int i=0 ; i < B.length ; i++){    
            System.out.println();
            for  (int j=0 ; j < B[i].length ; j++){
                System.out.print(B[i][j]+" ");
                  }
        }
System.out.println();
System.out.println();
System.out.println("Addition Of Matrices: ");
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
C[i][j]=A[i][j]+B[i][j];
System.out.print(C[i][j]+" ");
}
System.out.println();
}
}
}

Thanks

Ads









Related Tutorials/Questions & Answers:
matrix addition
matrix addition  hai
matrix addition
matrix addition  hai
Advertisements
Matrix Addition using RMI in Java
Matrix Addition using RMI in Java  Source Code for Matrix Addition using RMI in Java
matrix adddition
matrix adddition   how to write a program matrix addition in java
Java Matrix Addition Example
Java Matrix Addition Example In this tutorial, you will learn how to find the sum of two matrices. You may have solved many Matrix Operations in Mathematics... 2 3 4 5 6 2 1 3 Matrix B: 5 2 3 5 5 1 2 2 5 Addition Of Matrices
Addition of JComboBoxItem
Addition of JComboBoxItem  how to add JComboBoxItem cb1=1,cb2=1/9 into a JTextField. thanks
Matrix addition in java
Matrix addition in java In this section we will learn about addition of two...-dimensional array. Here we are going to develop a Java code for matrices addition, while adding two matrices the number of row and column of first matrix is equal
addition
Addition of two numbers
Addition of two numbers  addition of two numbers
matrix substraction
matrix substraction  hai
matrix substraction
matrix substraction  hai
column matrix
column matrix  columan wise total matrix
column matrix
column matrix  columan wise total matrix
transpose matrix
integers into the matrix and print the transpose of it. for this program u r given answer but if i entered 2 by 3 matrix it will not give answer ple check it once
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
transpose of matrix
transpose of matrix  write a program in java to declare a square matrices 'A' or order n which is less than 20.allow in user to input only positive integers into the matrix and print the transpose
matrix determination in java
matrix determination in java  hai
matrix polynamial addtion
matrix polynamial addtion  hai
ModuleNotFoundError: No module named 'math-addition'
ModuleNotFoundError: No module named 'math-addition'  Hi, My... 'math-addition' How to remove the ModuleNotFoundError: No module named 'math-addition' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'shivam-addition'
ModuleNotFoundError: No module named 'shivam-addition'  Hi, My... named 'shivam-addition' How to remove the ModuleNotFoundError: No module named 'shivam-addition' error? Thanks   Hi, In your python
MySQL Addition
MySQL Addition       MySQL Addition returns you the sum value of a specific column for a group in a table. The Aggregate function sum() is used to perform the addition in SQL
matrix
Magic Matrix in GUI
Magic Matrix in GUI  I want program in java GUI contain magic matrix for numbers
ModuleNotFoundError: No module named 'matrix'
ModuleNotFoundError: No module named 'matrix'  Hi, My Python... 'matrix' How to remove the ModuleNotFoundError: No module named 'matrix'... to install padas library. You can install matrix python with following command
ModuleNotFoundError: No module named 'the-matrix'
ModuleNotFoundError: No module named 'the-matrix'  Hi, My Python... 'the-matrix' How to remove the ModuleNotFoundError: No module named 'the-matrix' error? Thanks   Hi, In your python environment you
Parallel multiplication matrix in java
Parallel multiplication matrix in java  hello dear I need parallel multiply matrix in java algorithm to account speed up and efficiency great wishes
Preprocessor directive case for multiplication and addition
Preprocessor directive case for multiplication and addition  Preprocessor directive case for multiplication and addition include<stdio.h> define m 2+10 include<conio.h> int main() { int i; clrscr
MySQL Addition
MySQL Addition       MySQL Addition returns you the sum value of the total counts in a table... The Tutorial illustrate an example from 'MySQL Addition'. To understand the example
Matrix Multiplication in Java
(); //p holding the number of rows for the second matrix q = in.nextInt(); // q holding the number of column for the second matrix...Matrix Multiplication in Java In this Java tutorial we will demonstrate you
Ansoff Matrix
The Ansoff matrix or Ansoff Growth matrix is an effective marketing planning... growth strategy. According to the Ansoff matrix, a business growth depends upon... product in a new or existing market. Based on this, factor Ansoff matrix

Ads