id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

tmhscs@gmail.com arrays2d


  ____  ____       _                             
 |___ \|  _ \     / \   _ __ _ __ __ _ _   _ ___ 
   __) | | | |   / _ \ | '__| '__/ _` | | | / __|
  / __/| |_| |  / ___ \| |  | | | (_| | |_| \__ \
 |_____|____/  /_/   \_\_|  |_|  \__,_|\__, |___/
                                       |___/     
The following problems are all about two dimensional arrays!

Note: CodingBat does not fully support 2D arrays, so I cannot write a question that has a 2D array as they input or output. Instead, I will send multiple 1D arrays as parameters, and have the output for each question not be a 2D array.

Creating 2D Arrays: You can write: int[][] arr = new int[3][4];
The first dimension is how many 1D arrays or rows are in the 2D array.
The second dimension is how many values or columns are in each 1D array in the 2D array.
Alternatively, int[][] arr = { {1,2,3}, {4,5,6}, {7,8,9} }; would also create a 2D array.
And lastly, int[][] arr = {row1, row2, row3}; would also work if those rows are 1D arrays.

Iterating Through 2D Arrays: You'll need two for loops to go through all of the values in a 2D array.
I suggest something like the following that uses "r" and "c" as variable names.

for(int r=0; r<arr.length; r++) {
  for(int c=0; c<arr[r].length; c++) {
    // code here
  }
}

01. array2D_storageSpace H   array2D_storageSpace
02. array2D_sumAll H   array2D_sumAll
03. array2D_countNegatives H   array2D_countNegatives
04. array2D_largestValue H   array2D_largestValue
05. array2D_containsValue H   array2D_containsValue
06. array2D_average H   array2D_average
07. array2D_rowSums H   array2D_rowSums
08. array2D_colSums H   array2D_colSums
09. array2D_diagSums H   array2D_diagSums
10. array2D_sumCorners H   array2D_sumCorners
11. array2D_ticTacToe H   array2D_ticTacToe

Authoring docs

Copyright Nick Parlante 2017 - privacy