JAVA_CODINGS Telegram 61
42. Add two Matrix.
import java.util.*;

class AddTwoMatrix
{
int m, n;
int first[][] = new int[m][n];
int second[][] = new int[m][n];

AddTwoMatrix(int[][] first, int[][] second, int m, int n)
{
this.first = first;
this.second = second;
this.m = m;
this.n = n;
}

public static void main(String[] args)
{
int m, n, c, d;

Scanner in = new Scanner(System.in);

System.out.println("Enter the number of rows and columns of matrix");
m = in.nextInt();
n = in.nextInt();

int first[][] = new int[m][n];
int second[][] = new int[m][n];

System.out.println("Enter the elements of first matrix");

for (c = 0; c < m; c++)
{
for (d = 0; d < n; d++)
{
first[c][d] = in.nextInt();
}
}

System.out.println("Enter the elements of second matrix");

for (c = 0; c < m; c++)
{
for (d = 0; d < n; d++)
{
second[c][d] = in.nextInt();
}
}

System.out.println("\nElements of First matrix is : ");

for (c = 0; c < m; c++)
{
for (d = 0; d < n; d++)
{
System.out.print(first[c][d] + "\t");
}
System.out.println();
}

System.out.println("\nElements of Second matrix is : ");

for (c = 0; c < m; c++)
{
for (d = 0; d < n; d++)
{
System.out.print(second[c][d] + "\t");
}
System.out.println();
}

AddTwoMatrix a = new AddTwoMatrix(first, second, m, n);
//call by reference
a.addmatrix(a); //Passing Object
}

//Function for Adding two matrix and storing in third matrix
public void addmatrix(AddTwoMatrix a)
{
int c, d;
int sum[][] = new int[a.m][a.n];

for (c = 0; c < a.m; c++)
{
for (d = 0; d < a.n; d++)
{
sum[c][d] = a.first[c][d] + a.second[c][d];
}
}

System.out.println("\nSum of the two matrices is : ");

for (c = 0; c < a.m; c++)
{
for (d = 0; d < a.n; d++)
{
System.out.print(sum[c][d] + "\t");
}
System.out.println();
}
}
}

@java_codings



tgoop.com/java_codings/61
Create:
Last Update:

42. Add two Matrix.
import java.util.*;

class AddTwoMatrix
{
int m, n;
int first[][] = new int[m][n];
int second[][] = new int[m][n];

AddTwoMatrix(int[][] first, int[][] second, int m, int n)
{
this.first = first;
this.second = second;
this.m = m;
this.n = n;
}

public static void main(String[] args)
{
int m, n, c, d;

Scanner in = new Scanner(System.in);

System.out.println("Enter the number of rows and columns of matrix");
m = in.nextInt();
n = in.nextInt();

int first[][] = new int[m][n];
int second[][] = new int[m][n];

System.out.println("Enter the elements of first matrix");

for (c = 0; c < m; c++)
{
for (d = 0; d < n; d++)
{
first[c][d] = in.nextInt();
}
}

System.out.println("Enter the elements of second matrix");

for (c = 0; c < m; c++)
{
for (d = 0; d < n; d++)
{
second[c][d] = in.nextInt();
}
}

System.out.println("\nElements of First matrix is : ");

for (c = 0; c < m; c++)
{
for (d = 0; d < n; d++)
{
System.out.print(first[c][d] + "\t");
}
System.out.println();
}

System.out.println("\nElements of Second matrix is : ");

for (c = 0; c < m; c++)
{
for (d = 0; d < n; d++)
{
System.out.print(second[c][d] + "\t");
}
System.out.println();
}

AddTwoMatrix a = new AddTwoMatrix(first, second, m, n);
//call by reference
a.addmatrix(a); //Passing Object
}

//Function for Adding two matrix and storing in third matrix
public void addmatrix(AddTwoMatrix a)
{
int c, d;
int sum[][] = new int[a.m][a.n];

for (c = 0; c < a.m; c++)
{
for (d = 0; d < a.n; d++)
{
sum[c][d] = a.first[c][d] + a.second[c][d];
}
}

System.out.println("\nSum of the two matrices is : ");

for (c = 0; c < a.m; c++)
{
for (d = 0; d < a.n; d++)
{
System.out.print(sum[c][d] + "\t");
}
System.out.println();
}
}
}

@java_codings

BY Advance Java 👨‍💻


Share with your friend now:
tgoop.com/java_codings/61

View MORE
Open in Telegram


Telegram News

Date: |

On Tuesday, some local media outlets included Sing Tao Daily cited sources as saying the Hong Kong government was considering restricting access to Telegram. Privacy Commissioner for Personal Data Ada Chung told to the Legislative Council on Monday that government officials, police and lawmakers remain the targets of “doxxing” despite a privacy law amendment last year that criminalised the malicious disclosure of personal information. The public channel had more than 109,000 subscribers, Judge Hui said. Ng had the power to remove or amend the messages in the channel, but he “allowed them to exist.” Judge Hui described Ng as inciting others to “commit a massacre” with three posts teaching people to make “toxic chlorine gas bombs,” target police stations, police quarters and the city’s metro stations. This offence was “rather serious,” the court said. How to Create a Private or Public Channel on Telegram? Unlimited number of subscribers per channel
from us


Telegram Advance Java 👨‍💻
FROM American