Logic of maximun number in array in java
Answers
Answered by
0
Answer:
Java Program to find largest element in an array
Given an array, find the largest element in it.
Input : arr[] = {10, 20, 4} Output : 20 Input : arr[] = {20, 10, 20, 4, 100} Output : 100
Answered by
3
For an effortless approach we can directly sort the Array using sort( ) method of Arrays class in java.util package, which will sort the Array in ascending order and the last element in the Array will be the largest i.e. array[array.length - 1].
If we want to retain the order of the elements then we can transverse through the Array and compare each element using Math.max( ) to find the largest element.
Similar questions