Last active
December 16, 2015 06:28
-
-
Save enile8/5391472 to your computer and use it in GitHub Desktop.
A 2d array example in Java.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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