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

  1. Start with first element as max
  2. Compare each element with current max
  3. Update max if element is larger

Related Arrays exercises

Practice all Arrays exercises · Run this idea in the Java compiler