0% found this document useful (0 votes)
2 views3 pages

Sum

The document contains a Java program that prompts the user to input the number of rows and columns for a matrix. It then allows the user to fill the matrix with elements and calculates the sum of each row and each column. Finally, it prints the matrix elements along with the calculated sums for rows and columns.

Uploaded by

neelamsahun41
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Sum

The document contains a Java program that prompts the user to input the number of rows and columns for a matrix. It then allows the user to fill the matrix with elements and calculates the sum of each row and each column. Finally, it prints the matrix elements along with the calculated sums for rows and columns.

Uploaded by

neelamsahun41
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Program of printing sum of row and column:

import java.util.*;

public class sum_matrix

public static void amin (String args[])

Scanner br=new Scanner (System.in);

System.out.println("Enter the no. of rows");

int row=br.nextInt();

System.out.println("Enter the no of columns");

int col= br.nextInt();

int a[][]=new int[row][col];

// storing array

System.out.println("Array "+(row*col)+" Elements are:");

for(int i=0;i<row;i++)

for(int j=0;j<col;j++)

a[i][j]=br.nextInt();

}
}

//Print the elements

System.out.println("The array elements are:\n");

for (int i=0;i<row;i++)

for(int j=0;j<col;j++)

System.out.print(a[i][j]+ " ");

System.out.println();

for (int i=0;i<row;i++)

int sumrow=0;

for(int j=0;j<col;j++)

sumrow=sumrow+a[i][j];

System.out.print(" Sum of "+(i+1)+" row:"+sumrow);

System.out.println();
}

for (int i=0;i<col;i++)

int sumcol=0;

for(int j=0;j<row;j++)

sumcol=sumcol+a[j][i];

System.out.print(" Sum of "+(i+1)+" col : "+sumcol);

System.out.println();

You might also like