Skip to content

Commit 52c227c

Browse files
authored
Create FindMax.java
1 parent 3dd4c9d commit 52c227c

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

algorithms/FindMax.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.zetcode;
2+
3+
// brute force algorithm to find maximum value
4+
// in array
5+
6+
public class FindMax {
7+
8+
public static void main(String[] args) {
9+
10+
int[] values = {3, 7, 1, 15, 12, 6, 11, 9};
11+
12+
int max = values[0];
13+
14+
for (int i = 1; i < values.length; i++) {
15+
16+
if (values[i] > max) {
17+
max = values[i];
18+
}
19+
}
20+
21+
System.out.printf("The maximum is %d%n", max);
22+
}
23+
}

0 commit comments

Comments
 (0)