we will here, find the largest element inside an array using Java:
Algorithm :
Create the largest variable.
Thinking :
In the largest variable, store the zero indexing value of an array. start traversing using the for loop and compare every value if the value is greater than the largest element we will update the value in the largest variable. Hence, we can find the largest element inside an array.
Approach :
- create the largest variable and store the zero indexing value of an array.
- use a for-loop and compare it with other elements of an array.
- if any aspect is greater than the largest variable value, update the largest variable value with the element value.
- print the largest variable.
Output :
18