Java Program to Find Sum of Each Column of Matrix

Program to Find the Sum of Each Column of Matrix 2021

Java Program to Find the Sum of Each Column of Matrix

Here is   Sum Of Each Columns Of 2D Array In Java   Program Solution

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_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

Post a Comment

0 Comments