Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 80ffce4

Browse files
committed
FEAT Implemented method to print contents of an int array
1 parent 7f2f71c commit 80ffce4

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

‎src/PracticeAlgorithms.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ public static void printTwoDmIntArray(int[][] theArray) {
9494
}
9595

9696

97+
public static void printIntArray(int[] theArray) {
98+
for (int item : theArray) {
99+
System.out.printf("%d ", item);
100+
}
101+
System.out.println();
102+
}
103+
104+
97105
/**
98106
* static method that returns the transposition of an input matrix
99107
* */
@@ -144,7 +152,7 @@ public static int binarySearch(int key, int[] array) {
144152
/**
145153
* static recursive method that implements binary search
146154
* */
147-
public static int rank(int key, int[] array, int minIndex, int maxIndex) {
155+
private static int rank(int key, int[] array, int minIndex, int maxIndex) {
148156
if (minIndex > maxIndex) return -1;
149157
int midIndex = minIndex + (maxIndex - minIndex) / 2;
150158

@@ -180,6 +188,9 @@ public static void main(String[] args) {
180188
testIntArray[8] = 1;
181189
testIntArray[9] = 10;
182190

191+
int[] sortedTestIntArray = Arrays.copyOf(testIntArray, testIntArray.length);
192+
Arrays.sort(sortedTestIntArray);
193+
183194
testTwoDmBooleanArray[0][0] = true;
184195
testTwoDmBooleanArray[0][1] = false;
185196
testTwoDmBooleanArray[1][0] = false;
@@ -228,8 +239,13 @@ public static void main(String[] args) {
228239
System.out.printf("31!: %d\n", fact(31)); // N > 31 causes overflow
229240
System.out.println();
230241

242+
System.out.println("- The Sorted Array");
243+
printIntArray(sortedTestIntArray);
244+
System.out.println();
245+
231246
System.out.println("- Binary Search: key = 5");
232-
System.out.println(binarySearch(5, testIntArray));
247+
System.out.println("index: " + binarySearch(5, testIntArray));
233248
System.out.println();
249+
234250
}
235251
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /