0

public class LargestInArray {
    public static void main(String[] args) {
        int[] arr = {10, 25, 5, 40, 15};
        int max = arr[0];
        for(int num : arr) {
            if(num > max) {
                max = num;
            }
        }
        System.out.println("Largest element is: " + max);
    }
}

Find the largest element in an array in Java
Working Code Asked question November 18, 2025
Sorry, you do not have permission to read comments.