Skip to content

Instantly share code, notes, and snippets.

@enile8
Last active December 16, 2015 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enile8/5391472 to your computer and use it in GitHub Desktop.
Save enile8/5391472 to your computer and use it in GitHub Desktop.
A 2d array example in Java.
public class ArrayTest {
public static void main(String[] args) {
final int ROW = 3;
final int COL = 4;
int[][] numbers = new int[ROW][COL];
int total = 0,
value = 0;
for (int i = 0; i < ROW; i++)
{
for (int n = 0; n < COL; n++)
{
numbers[i][n] = value;
value += 1;
}
}
for (int i = 0; i < ROW; i++)
{
for (int n = 0; n < COL; n++)
{
total += numbers[i][n];
System.out.println(numbers[i][n]);
}
}
System.out.println("The total is: " + total);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment