In this tutorial, Java program to find the largest number in array.
Here is simple algorithm to find larget element in the array.
- Initialize lrg with arr[0] i.e. first element in the array.
- If current element is greater than lrg, then set lrg to current element.
import java.util.Scanner;
public class Finder
{
public static void main(String args[])
{
int lrg, size, i;
int numArr[] = 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
Output:
Enter Array Size : 5
Enter Array Elements : 34 85 95 25 75
Searching for the largest Number….
Enter Array Elements : 34 85 95 25 75
Searching for the largest Number….
Largest Number = 95
That’s all about Java program to find largest number in array.