Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleStrings in Java
 intint[][] cinema = new int[105][105]; 
for (int j = 0; j < cinema.length; j++) {
	for (int i = 0; i < cinema[j].length; i++) {
    	cinema[j][i] = 0;       
    }
}
Instead of one bracket used in one dimensional array, we will use two e.g. int[][] to define two-dimensional array. 

Code Block
languagepy
titleStrings in Python
cinema = []
for j in range(105):
	column = []
    for i in range(105):
		Column.append(0)
	Cinema.append(column)

In Python, we declare the 2D array (list) like a list of lists. First, we create an empty one-dimensional list. Then we generate 5 more lists (columns) using a for loop, fill each list with 5 zeros using a nested loop and add the list to the original list as a new item.

The first number indicates the number of columns, the second is the number of rows, we could treat it the other way around as well, for example, matrices in mathematics have the number of rows come first.

We've just created a table full of zeros.

...