-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
6.6.4. Двухмерный массив. Таблица умножения;
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ru.j4j.array; | ||
|
||
public class Matrix { | ||
public static int[][] multiple(int size) { | ||
int[][] table = new int[size][size]; | ||
for (int row = 0; row < table.length; row++) { | ||
for (int cell = 0; cell < table[row].length; cell++) { | ||
table[row][cell] = (row + 1) * (cell + 1); | ||
} | ||
} | ||
return table; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ru.j4j.array; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class MatrixTest { | ||
@Test | ||
public void when2on2() { | ||
int size = 2; | ||
int[][] result = Matrix.multiple(size); | ||
int[][] expected = { | ||
{1, 2}, | ||
{2, 4} | ||
}; | ||
assertThat(result).isDeepEqualTo(expected); | ||
} | ||
|
||
@Test | ||
public void when5on5() { | ||
int size = 5; | ||
int[][] result = Matrix.multiple(size); | ||
int[][] expected = { | ||
{1, 2, 3, 4, 5}, | ||
{2, 4, 6, 8, 10}, | ||
{3, 6, 9, 12, 15}, | ||
{4, 8, 12, 16, 20}, | ||
{5, 10, 15, 20, 25} | ||
}; | ||
assertThat(result).isDeepEqualTo(expected); | ||
} | ||
} |