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
→