Write a Java Program to Find Largest Element of an Array

Java Program to Find Largest Element of an Array

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java  language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Java Program to Find Largest Element of an Array
Java Program to Find Largest Element of an Array

Write a Java Program to Find Largest Element of an Array

PROGRAM: Java Program to Find Largest Element of an Array

/*Java Program to Find Largest Element of an Array*/

public class Largest {

public static void main(String[] args) {
double[] numArray = { 23.4, -34.5, 50.0, 33.5, 55.5, 43.7, 5.7, -66.5 };
double largest = numArray[0];

for (double num: numArray) {
if(largest < num)
largest = num;
}

System.out.format(“Largest element = %.2f”, largest);
}
}

Leave a Reply

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