Skip to content

Commit 3cb87ca

Browse files
committed
FEAT Implemented method to print formatted contents of an int matrix
1 parent 002ca4f commit 3cb87ca

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/PracticeAlgorithms.java

+14-5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ public static void printTwoDmBooleanArray(boolean[][] theArray) {
4040
}
4141
}
4242

43+
public static void printTwoDmIntArray(int[][] theArray) {
44+
45+
for (int[] rows : theArray) {
46+
for (int cols : rows) {
47+
System.out.printf("[%d] ", cols);
48+
}
49+
System.out.println();
50+
}
51+
}
52+
4353
/**
4454
* static method that returns the transposition of an input matrix
4555
* */
@@ -60,7 +70,6 @@ public static int[][] matrixTransposition(int[][] theMatrix) {
6070

6171
public static void main(String[] args) {
6272
Random generator = new Random();
63-
int i = 0;
6473

6574
double testX = 0.1;
6675
double testY = 0.5;
@@ -75,11 +84,10 @@ public static void main(String[] args) {
7584
testTwoDmBooleanArray[2][0] = true;
7685
testTwoDmBooleanArray[2][1] = false;
7786

78-
for (int[] rows : testIntMatrix) {
79-
for (int cols : rows) {
80-
testIntMatrix[i][cols] = generator.nextInt(10);
87+
for (int i = 0; i < testIntMatrix.length; i++) {
88+
for (int j = 0; j < testIntMatrix[i].length; j++) {
89+
testIntMatrix[i][j] = generator.nextInt(10);
8190
}
82-
i++;
8391
}
8492

8593
System.out.println(isBetweenZeroAndOne(testX, testY));
@@ -88,5 +96,6 @@ public static void main(String[] args) {
8896

8997
printTwoDmBooleanArray(testTwoDmBooleanArray);
9098
System.out.println();
99+
printTwoDmIntArray(testIntMatrix);
91100
}
92101
}

0 commit comments

Comments
 (0)