Find Maximum in Java: Explanation & Practice
Find the largest element in an array
Problem summary
Find the maximum value in the array [23, 45, 12, 67, 34].
Starter code
public class Main {
public static void main(String[] args) {
int[] arr = {23, 45, 12, 67, 34};
// Find and print maximum
// Print: Maximum: <result>
}
}Expected output and test cases
- Find max value
Maximum: 67
Hints
- Start with first element as max
- Compare each element with current max
- Update max if element is larger
Related Arrays exercises
- Practice Declare and Print Array in Java
- Practice Sum of Array in Java
- Practice Calculate Average in Java
Practice all Arrays exercises · Run this idea in the Java compiler