Java Program to Find Largest Element in an Array

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 SNIPPET
public 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

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this Java program, we will learn how to find the GCD of two numbers using Java.  GCD (Greatest Common...
  • Java
  • December 3, 2024
In this Java Program, you’ll learn how to swap two numbers using the Java programming language.  How to Swap Two...
  • Java
  • December 2, 2024
In this Java tutorial, we will learn how to add two integers in JAVA and storing the integer in an...
  • Java
  • December 2, 2024