SHARE
TWEET

Untitled

advictoriam Jan 17th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top