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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
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<size i numarr scan.nextint system.out.print for the largest number.... lrg="numArr[0];" if number=" +lrg); } } </pre>"></size> |
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.
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.