Question

Write java program to find sum of two matrices. Define appropriate class, constructor and methods in your program. Make necessary assumptions.

07 Aug 2023
Answer :
Word Count : 614

Here's a Java program that calculates the sum of two matrices using classes, constructors, and methods:


class Matrix {
    private int rows;
    private int cols;
    private int[][] data;

    public Matrix(int rows, int cols) {
        this.rows = rows;
        this.cols = cols;
        this.data = new int[rows][cols];
    }

    public void setData(int[][] data) {
        this.data = data;
    }

    public void inputMatrix() {
        System.out.println("Enter matrix elements:");
        Scanner scanner = new Scanner(System.in);
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
  ___ ______ ___ ____ ______ ______.
______ _______ ____ ______ ____ ________.
______ ____ __________ __________ _______ _______ _______ ______ _______.
_______ ________ ___ _________ __________ ____ ___ _____ ____ __________ ____ ________.
__________ _______ ___ ____ _____ ________ _______ _______ ____ _________ _________ ____.
____ _________ _____ ________ ___ _______ ______ _____ ____ _____.
__________ ___ ___ ___ __________ ____ _______ ___ __________ _______ ________ ___.
________ ____ _______ __________ _____ _________ __________.
__________ ______ ___ ________ _______ ______ _____.
_________ ______ ______ _______ ____ _____ _________ __________ ___.
_______ _____ ____ _____ _______ ______ ________ _____ _____.
_________ ___ ____ _________ _______ ____ _________ ____ ______ _________ _____ ______.
_______ _______ ______ ______ __________ ________ _____ _________ ____ _________ _____.
________ ______ _________ _______ ________ __________ _______ __________ _________ _________ __________.
_____ __________ _____ ________ __________ ___.
__________ __________ ________ ______ _________ ________.
_______ ______ ______ ______ ___ ______ ___ ___ _______ ______ ______.
________ ____ ________ _____ _____ ________.
____ ______ _______ _________ ______ _______ ___ ___ ______.
_________ ________ _______ ____ __________ _______ ____.
____ __________ ____ ___ __________ ___ _________.
__________ ____ ________ ________ _____ __________.
_______ ____ _____ ________ ____ _________ _____ ____ ___ ______ _______.
___ ________ _________ ______ __________ ___.
______ ________ _______ ___ ________ ________.
________ ___ ________ ___ ___ _________ ___ ____ _______ _________.
_____ ____ __________ ______ __________ __________ ______ ________.
________ _____ ____ _________ _______ _________ _______ ____ _________ __________.
______ ____ __________ _________ ________ ________.
______ _________ __________ _______ ___.
___ _______ _______ ________ _________ ________ _______ __________ __________ ___.
__________ _______ __________ ___ ______ _______ ____ ________.
_________ _______ ________ _______ ___ ____.
__________ ____ _____ ___ _______ __________ ________ ___ ________ __________ _______ _________.
__________ ______ _______ _________ _______ ____ ___ _________ _____ _______.
_______ ____ _____ ________ ___ _____ __________ _________ ________.
_____ ______ ______ ________ ___ _________.
________ ___ ___ ______ _________.
__________ ________ __________ ______ ____.
_______ _______ ___ ________ _____.
___ ____ ________ ___ ___ ________ ___.
__________ _________ _________ _____ ______ _______ _________ ____ _____ ________ _____ _______.
______ _______ _____ _________ ________ ________ ______ ______ _______ _________.
__________ ___ _____ ______ ____ ______ ____ ___ __________ __________ ______ __________.
______ ________ ______ ______ _______ ______.
___ __________ _____ ____ ________ _______ ____ ______.
_____ __________ ______ __________ __________ ____ _______ _______ ___.
____ _________ ___ _____ ________ ________ _______ ____.
____ ______ _______ __________ __________ ________ ______ ________.
___ _________ __________ ________ _____ ___ _________ ___ __________ ___ ___.
_______ ________ _______ _____ ______ _________ ________ ___ ___.
____ __________ _________ ____ _________.
________ ____ _________ __________ ________ ___ ___ __________ _______ _______.
____ ________ ______ ________ ____.
_________ _____ ___ _______ ____ __________.
_________ _____ ____ ____ _____ _______.
Get Full Answer on WhatsApp

IGNOU NEWS
Assignment Submission Last Date Extended Till 30 June 2026 Click Here★★★IGNOU June 2026 TEE Date Sheet Released Click Here★★★
Top
📞
Call Support Instant phone assistance Write java program to find sum of two matrices. Define appropriate cla
🟢
WhatsApp Chat Fast live messaging
Email Us Business enquiries & support