Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.
In this software testing question, we will write a program in Java that finds and prints the addition result of any two given matrices.
import java.util.Scanner;
public class AddMatrix
{
public static void main(String[] args)
{
int i, j;
int[][] m = new int[3][3];
int[][] n = new int[3][3];
int[][] o = new int[3][3];
Scanner sc = new Scanner(System.in);
System.out.print("Enter the nine elements for the first matrix: ");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
m[i][j] = sc.nextInt();
}
}
System.out.print("Enter the nine elements for the second matrix: ");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
n[i][j] = sc.nextInt();
}
}
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
o[i][j] = m[i][j] + n[i][j];
}
}
System.out.println("Addition of Two Matrix");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
System.out.print(o[i][j]+ " ");
}
System.out.print("
");
}
}
}
Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.
Start Free TestingEarn resume-worthy Selenium certifications that help you land a top job.
Learn MoreTest orchestration and execution cloud of 3000+ browsers and OS
24/7 support
Enterprise grade security
Fastest test execution cloud