Given a 3×3 matrix the task is to sum individual row of the matrix.
Example: Consider the 3×3 matrix
| 1 | 5 | 8 |
| 2 | 3 | 7 |
| 5 | 1 | 4 |
Sum of Row 1: 14
Sum of Row 2: 12
Sum of Row 3: 10
Java
import java.util.*;
class SumEachRow
{
public static void main(String args[])
{
int sum=0;
Scanner sc=new Scanner(System.in);
int ar[][]=new int[3][3];
System.out.println("Enter matrix elements:-");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
ar[i][j]=sc.nextInt();
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
sum=sum+ar[i][j];
}
System.out.println("Sum of Row "+(i+1)+": "+sum);
sum=0;
}
}
}Java