Sum of Each Row

Given a matrix of custom size the task is to calculate and print sum of each row.

Example: Consider a matrix

147
328
569

Sum of row 1: 1+4+7 = 12.
Sum of row 2: 3+2+8 = 13.
Sum of row 3: 5+6+9 = 20.

The program should output only the sum with the row number.

Java
import java.util.*;
public class SumRow
{
    public static void main(String args[])
    {
        int row=0,col=0,sum=0;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter no.of rows: ");
        row=sc.nextInt();
        System.out.print("Enter no.of columns: ");
        col=sc.nextInt();
        int ar[][]=new int[row][col];
        System.out.println("Enter matrix elements:-");
        for(int i=0;i<row;i++)
        {
            for(int j=0;j<col;j++)
            {
                ar[i][j]=sc.nextInt();
            }
        }
        for(int i=0;i<row;i++)
        {
            for(int j=0;j<col;j++)
            {
                sum=sum+ar[i][j];
            }
            System.out.println("Sum of Row "+(i+1)+": "+sum);
            sum=0;
        }
    }
}
Java