Skip to content

Commit 7dbf9e0

Browse files
committed
Index of Max is done.
1 parent 3995168 commit 7dbf9e0

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

ch07/indexOfMax.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class indexOfMax {
2+
public static int indexOfMaxMethod(int[] numbers) {
3+
int result = 0;
4+
int maxVal = numbers[0];
5+
6+
for (int i = 1; i < numbers.length; i++) {
7+
if (numbers[i] > maxVal) {
8+
maxVal = numbers[i];
9+
result = i;
10+
}
11+
}
12+
13+
return result;
14+
}
15+
16+
public static void main(String[] args) {
17+
int[] test = {3, 7, 1, 9, 12};
18+
19+
System.out.println(indexOfMaxMethod(test));
20+
}
21+
}

0 commit comments

Comments
 (0)