In this Java program , we will learn how to Find Largest Element in an Array in your Java program.
How to Find Largest Element in an Array using JAVA?
Example 1:
RUN CODE SNIPPETpublic class Main { public static void main(String[] args) { double[] numArray = { 30.5, -29.5, 100, 75.5, 98.5, 34.9, 77, -21.9 }; double largest = numArray[0]; for (double num: numArray) { if(largest < num) largest = num; } System.out.format("Largest element = %.2f", largest); } }
OUTPUT
Largest element = 100.00