Here
is the Program to Find the Sum of Each Row and Each Column of Matrix 2021.
Checkout:- Neon Number In Java - Solved Program
Checkout:- Spy Number In Java - Solved Program
We
are uploading these types of program. However, if you need fully
compiled solution of any type of Java program then simply leave a
comment below, we will help you at the earliest. 😊😊
import java.util.*;
public class Sum_of_Rows_And_Columns
{
public static void main()
{
int s=0;
int d=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of Rows");
int r=sc.nextInt();
System.out.println("Enter the number of Columns");
int c=sc.nextInt();
int arr[][]=new int[r][c];
System.out.println("Enter the elements of Matrix");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
arr[i][j]=sc.nextInt();
}
}
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println("");
}
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
s=s+arr[i][j];
}
System.out.println("Sum Of Row "+i+"= "+s);
s=0;
}
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
d=d+arr[j][i];
}
System.out.println("Sum Of Column "+i+"= "+d);
d=0;
}
}
}
------------
OUTPUT:-
------------
Enter the number of Rows
4
Enter the number of Columns
4
Enter the elements of Matrix
1
5
9
8
7
4
5
6
3
2
1
4
5
2
3
6
1 5 9 8
7 4 5 6
3 2 1 4
5 2 3 6
Sum Of Row 0= 23
Sum Of Row 1= 22
Sum Of Row 2= 10
Sum Of Row 3= 16
Sum Of Column 0= 16
Sum Of Column 1= 13
Sum Of Column 2= 18
Sum Of Column 3= 24
-------------------
Checkout:- Print Two Dimensional/Multidimensional Array Java
Checkout:- Java Program to Add Two Matrices
0 Comments
Just write down your question to get the answer...