public static void main(String[] args) {
int [][] array = {
{1,2,3,4,5},
{6,7,8,9,10},
{11,12,13,14,15},
{16,17,18,19,20},
};
for(int row =0; row < array.length; row ++) {
int total = 0;
for(int column = 0; column < array[0].length; column++) {
total = total + array[row] [column];
}
System.out.println("Sum for Row " + row + " , is = " + total);
}
}
//OUTPUT:
Sum for Row 0 , is = 15
Sum for Row 1 , is = 40
Sum for Row 2 , is = 65
Sum for Row 3 , is = 90
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter