codescracker


java

Java Program to Find Largest Element in Array



« Previous Program Next Program »


Find Largest Element in Array

To find the largest element in an array in Java Programming, first you have to ask to the user to enter the size and elements of the array. Now start finding for the largest element in the array to display the largest element of the array on the output screen as shown in the following program.

Java Programming Code to Find Largest Element in Array

Following Java Program ask to the user to enter array size and then array element to find the largest element present in the array, then display the result on the screen:

/* Java Program Example - Find Largest Element in Array */
		
import java.util.Scanner;

public class JavaProgram
{
   public static void main(String args[])
   {
       int large, size, i;
       int arr[] = new int[50];
       Scanner scan = new Scanner(System.in);
	   
       System.out.print("Enter Array Size : ");
       size = scan.nextInt();
	   
       System.out.print("Enter Array Elements : ");
       for(i=0; i<size; i++)
       {
           arr[i] = scan.nextInt();
       }
	   
       System.out.print("Searching for the Largest Number....\n\n");
	   
       large = arr[0];
	   
       for(i=0; i<size; i++)
       {
           if(large < arr[i])
           {
               large = arr[i];
           }
           
       }
	   
       System.out.print("Largest Number = " +large); 
   }
}

When the above Java Program is compile and executed, it will produce the following output:

Java Program find largest element in array

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test