Array-promo
Matrix-promo

Question

Program to find sum of each row in the matrix

				
					Matrix =  [9, 8, 7]
          [6, 5, 4]
          [3, 2, 1]
          
SUM OF EACH ROW IN THE MATRIX
24
15
6
				
			

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;
public class SumOfEachRowInMatrix  
{  
    public static void main(String[] args)
    {  
        int row=0, col=0,sum=0,i=0,j=0;  
        int a[][];
        
        
        Scanner sc=new Scanner(System.in);
        System.out.println("ENTER THE ROW OF MATRIX");
        row=sc.nextInt();
        System.out.println("ENTER THE COLUMN OF MATRIX");
        col=sc.nextInt();

        a=new int[row][col];
        System.out.println("ENTER THE ELEMENTS IN MATRIX");
        for(i=0;i< row;i++)
        {
            for(j=0;j< col;j++)
            {
                a[i][j]=sc.nextInt();
            }
        }
            
        System.out.println("SUM OF EACH ROW IN THE MATRIX: ");
        for(i=0;i< row;i++)
        {
            for(j=0;j< col;j++)
            {
                sum=sum+a[i][j];
                    
            }
            System.out.println(sum);
            sum=0;
        }
        

        
        
    }  
}

				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *