Question

JAVA Program

1. Write a java program to find the sum of the elements on the diagonal of a matrix. 

2. Write a java program to add two matrices. 

3. Write a java program to find a given value in a matrix. 

4. Write a java program to multiply two matrices. 

5. Write a java program to find the transpose of a matrix.

3 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

Ans. to Q1

Program ->

import java.util.*;
class SumElementsDiagonal
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("\nEnter Number of rows of a Matrix: ");
int rows=sc.nextInt();
System.out.print("\nEnter Number of columns of a Matrix: ");
int cols=sc.nextInt();
int m1[][],m2[][];
m1=new int[rows][cols];
System.out.println("\nEnter Elements of Matrix- m1: \n");
for(int r=0;r


Ans. to Q2

Program ->

import java.util.*;
class AddMatrices
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("\nEnter Number of rows of a Matrix: ");
int rows=sc.nextInt();
System.out.print("\nEnter Number of columns of a Matrix: ");
int cols=sc.nextInt();
int m1[][],m2[][],m3[][];
m1=new int[rows][cols];
m2=new int[rows][cols];
m3=new int[rows][cols];
System.out.println("\nEnter Elements of Matrix- m1: \n");
for(int r=0;r

Ans. to Q3

Program ->

import java.util.*;
class SearchValMatrix
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("\nEnter Number of rows of a Matrix: ");
int rows=sc.nextInt();
System.out.print("\nEnter Number of columns of a Matrix: ");
int cols=sc.nextInt();
int m1[][]=new int[rows][cols];
System.out.println("\nEnter Elements of Matrix- m1: \n");
for(int r=0;r

Ans. to Q4

Program ->

import java.util.*;
class MultiplyMatrices
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("\nEnter Number of rows of a Matrix: ");
int rows=sc.nextInt();
System.out.print("\nEnter Number of columns of a Matrix: ");
int cols=sc.nextInt();
int m1[][],m2[][],m3[][];
m1=new int[rows][cols];
m2=new int[rows][cols];
m3=new int[rows][cols];
System.out.println("\nEnter Elements of Matrix- m1: \n");
for(int r=0;r

Ans. to Q5

Program ->

import java.util.*;
class TransposeMatrix
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("\nEnter Number of rows of a Matrix: ");
int rows=sc.nextInt();
System.out.print("\nEnter Number of columns of a Matrix: ");
int cols=sc.nextInt();
int m1[][],m2[][];
m1=new int[rows][cols];
m2=new int[rows][cols];
System.out.println("\nEnter Elements of Matrix- m1: \n");
for(int r=0;r


answered by: Zahidul Hossain
Add a comment
Know the answer?
Add Answer to:
JAVA Program
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT