Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ArrayOps
- {
- /**
- This method sums up both rows of a two-dimensional array
- (the only parameter to the method) and returns the greater sum.
- @param theArray, a 2-D array of integers
- @return, the greater row sum
- */
- public static int bigSum(int[][] theArray)
- {
- int sumOne = 0;
- int sumTwo = 0;
- int[] rowOne = theArray[0];
- int[] rowTwo = theArray[1];
- for(int i = 0; i < rowOne.length; i++)
- {
- sumOne += rowOne[i];
- }
- for(int i = 0; i < rowTwo.length; i++)
- {
- sumTwo += rowTwo[i];
- }
- return (sumOne > sumTwo) ? sumOne : sumTwo;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement