0% found this document useful (0 votes)
12 views1 page

D2 Row Coloumn Add

The document contains a Java program that reads a matrix from user input and calculates the sum of each row and each column. It prompts the user to enter the number of rows and columns, then the elements of the matrix. Finally, it prints the elements of each row along with their sums, followed by the sums of each column.

Uploaded by

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

D2 Row Coloumn Add

The document contains a Java program that reads a matrix from user input and calculates the sum of each row and each column. It prompts the user to enter the number of rows and columns, then the elements of the matrix. Finally, it prints the elements of each row along with their sums, followed by the sums of each column.

Uploaded by

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

Class matrix2 1/1

1 import java.util.*;
2 class matrix2
3 {
4 public static void main()
5 {
6 Scanner sc=new Scanner(System.in);
7 System.out.println("Enter the number of row and column");
8 int m=sc.nextInt();
9 int n=sc.nextInt();
10 int a[][]=new int [m][n];
11 int i,j,sum=0;
12 System.out.println("Enter the elements of the array ");
13 for(i=0;i<m;i++)
14 {
15 for(j=0;j<n;j++)
16 {
17 a[i][j]=sc.nextInt();
18 }
19 }
20 System.out.println("addition of row is");
21 for(i=0;i<m;i++)
22 {
23 sum=0;
24 for(j=0;j<n;j++)
25 {
26 System.out.print(a[i][j]+"\t");
27 sum=sum+a[i][j];
28 }
29 System.out.print(sum);
30 System.out.println();
31 }
32 int sum1;
33 for(i=0;i<n;i++)
34 {
35 sum1=0;
36 for(j=0;j<m;j++)
37 {
38 sum1=sum1+a[j][i];
39 }
40 System.out.print(sum1+"\t");
41 }
42 }
43 }

Sep 5, 2021 9:30:28 AM

You might also like