Java Program to Find Sum Of Each Row Of Matrix

ISC Java Program to Find Sum Of Rows Of Matrix 2021

Java Program to Find Sum Of Rows Of Matrix
 Here is  the  Solved Java Program to Find Sum Of Rows Of Matrix - ISC Computer JAVA.
 
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  
 {  
   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[i][j];  
       }  
       System.out.println("Sum of Row "+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  
 4  
 5  
 6  
 7  
 8  
 9  
 Input Matrix Is  
 1 2 3   
 4 5 6   
 7 8 9  
 Sum of Row 0 = 6  
 Sum of Row 1 = 15  
 Sum of Row 2 = 24  
 ---------------- 

Checkout:- Sort Matrix in Ascending Order Java

Checkout:-  Program to Sort 2D array in Descending Order Java

Post a Comment

0 Comments