id/email | |
password | |
forgot password | create account |
about | help | code help+videos | done | prefs |
Return the sum of the specified column of the 2D array nums. The columnToSum parameter is the column that should be summed. If the columnToSum does not exist in nums, return -1. Important Note: Copy the following two methods into the window and don't change array2DRowAverage. CodingBat does not allow 2D array parameters, so this method is accepting the number of rows, number of columns, and a 1D array. The first method takes this information and creates a 2D array named nums that you will be using. The columnToSum parameter is the column that should be summed. Enter your code into method array2DColumnSumB: public int array2DColumnSum(int rows, int cols, int[] array, int columnToSum) { int[][] array2D = new int[rows][cols]; int idx = 0; for (int r=0; r<rows; r++) { for (int c=0; c<cols; c++) { array2D[r][c] = array[idx]; idx++; } } return array2DColumnSumB(array2D, columnToSum); } public int array2DColumnSumB(int[][] nums, int columnToSum) { } array2DColumnSum(2, 4, [2, 4, 6, 8, 10, 12, 14, 16], 0) → 12 array2DColumnSum(4, 2, [2, 4, 6, 8, 10, 12, 14, 16], 1) → 40 array2DColumnSum(3, 2, [2, 4, 6, 8, 10, 12], 1) → 24 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 10 Post-solution available
Copyright Nick Parlante 2017 - privacy