This commit is contained in:
Rémi Heredero 2022-03-03 15:25:00 +01:00
parent 64a05245d6
commit de1a14864e
2 changed files with 2 additions and 2 deletions

View File

@ -12,7 +12,7 @@ import java.util.Random;
*/ */
public class NumberAnalyzer { public class NumberAnalyzer {
public static void main(String[] args) { public static void main(String[] args) {
int[] array = createRandomArray(100, 100); int[] array = createRandomArray(100, 51);
displayArray(array); displayArray(array);
int position = firstRepeatedNumber(array); int position = firstRepeatedNumber(array);
System.out.println("The first repeated element is at location " + position); System.out.println("The first repeated element is at location " + position);
@ -27,7 +27,7 @@ public class NumberAnalyzer {
*/ */
public static int firstRepeatedNumber(int[] inputArray) { public static int firstRepeatedNumber(int[] inputArray) {
for (int i = 0; i < inputArray.length; i++) { for (int i = 0; i < inputArray.length; i++) {
if (inputArray[i] == inputArray[i + 1]) if (inputArray[i] == inputArray[i + 1]) // can't work, for should finish to lenght-1
return i; return i;
} }
return -1; return -1;