Created
June 17, 2016 12:20
-
-
Save Yurlov/5947b72443d46fcb3bbb2ab16dce0a43 to your computer and use it in GitHub Desktop.
Prog.kiev.ua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MatrixMaxSumRowFinder { | |
public static void main(String[] args) { | |
int[][] matrix = {{1,11,11,1,3}, | |
{1,1,2,1,4}, | |
{4,1,9,1,5}, | |
{1,2,3,4,5,}}; | |
System.out.println("Index of MaxSumRow: "+findMaxSumRow(matrix)); | |
} | |
private static int findMaxSumRow(int[][]matrix){ | |
int sum1 = 0; | |
int maxSum = 0; | |
for (int i = 0; i < matrix.length; i++){ | |
int sum = 0; | |
for (int j = 0; j < matrix[i].length; j++){ | |
sum += matrix[i][j]; | |
} | |
if (sum > sum1){ | |
sum1 = sum; | |
maxSum = i; | |
} | |
} | |
return maxSum; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment