diff --git a/README.md b/README.md index d60d5104c385..06354c5af1b6 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ + # The Algorithms - Java [![Build](https://github.com/TheAlgorithms/Java/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/TheAlgorithms/Java/actions/workflows/build.yml) diff --git a/src/main/java/com/thealgorithms/arrays/MaximumElement.java b/src/main/java/com/thealgorithms/arrays/MaximumElement.java new file mode 100644 index 000000000000..886aa271225b --- /dev/null +++ b/src/main/java/com/thealgorithms/arrays/MaximumElement.java @@ -0,0 +1,29 @@ +package com.thealgorithms.arrays; + +/** + * Finds the maximum element in an array. + */ +public final class MaximumElement { + + private MaximumElement() { + // utility class + } + + /** + * Returns the maximum element in the array. + * + * @param arr input array + * @return maximum value + */ + public static int max(int[] arr) { + int max = Integer.MIN_VALUE; + + for (int num : arr) { + if (num > max) { + max = num; + } + } + + return max; + } +}