Advertisement
advictoriam

Untitled

Jan 17th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. public class ArrayOps
  2. {
  3.    /**
  4.       This method sums up both rows of a two-dimensional array
  5.       (the only parameter to the method) and returns the greater sum.
  6.       @param theArray, a 2-D array of integers
  7.       @return, the greater row sum
  8.    */
  9.    public static int bigSum(int[][] theArray)
  10.    {
  11.       int sumOne = 0;
  12.       int sumTwo = 0;
  13.      
  14.       int[] rowOne = theArray[0];
  15.       int[] rowTwo = theArray[1];
  16.       for(int i = 0; i < rowOne.length; i++)
  17.       {
  18.          sumOne += rowOne[i];
  19.       }
  20.       for(int i = 0; i < rowTwo.length; i++)
  21.       {
  22.          sumTwo += rowTwo[i];
  23.       }
  24.       return (sumOne > sumTwo) ? sumOne : sumTwo;
  25.    }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement