Here is Sum Of Each Columns Of 2D Array In Java Program Solution
Checkout:- Rotate Matrix 90 Degrees Clockwise | Clockwise Rotation Matrix
Checkout:- Symmetric Matrix Program In Java
import java.util.*;
public class Sum_of_Columns
{
public static void main()
{
int s=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();
}
}
System.out.println("Input Matrix Is");
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[j][i];
}
System.out.println("Sum Of Column "+i+"= "+s);
s=0;
}
}
}
------------
OUTPUT:-
------------
Enter the number of Rows
3
Enter the number of Columns
3
Enter the elements of Matrix
1
2
3
6
5
4
7
8
9
Input Matrix Is:-
1 2 3
6 5 4
7 8 9
Sum Of Column 0 = 14
Sum Of Column 1 = 15
Sum Of Column 2 = 16
-------------------
Checkout:- Find Transpose of a Matrix
Checkout:- Program to Find the Sum of Each Row and Each Column of Matrix
0 Comments
Just write down your question to get the answer...