Skip to content

Commit 002a648

Browse files
authored
feat: add maximum element in array implementation
1 parent 7d57c57 commit 002a648

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.thealgorithms.arrays;
2+
3+
public class MaximumElement {
4+
public static int findMax(int[] arr) {
5+
int max = Integer.MIN_VALUE;
6+
7+
for (int num : arr) {
8+
if (num > max) {
9+
max = num;
10+
}
11+
}
12+
13+
return max;
14+
}
15+
16+
public static void main(String[] args) {
17+
int[] arr = {1, 5, 3, 9, 2};
18+
System.out.println("Maximum element: " + findMax(arr));
19+
}
20+
}

0 commit comments

Comments
 (0)