Java program to find the largest and smallest in an array

Java Program to find the largest and smallest in an array

 

Hi guys:) in this article let’s see how to find the largest and smallest number from an array which is taken as input from the user.To know more about arrays in java click here.

Algorithm:

1)Start
2)Take the input size of an array and elemnts in an array from the user.
3)Assign the first element of an array as a smallest and largest.
4)Go the comparing each element with the largest and smallest.
5)If the current comparing element is larger than the assigned element then assign the current elemnt to largest variable.
6)If the current comparing element is smaller than the assigned element then assign the current elemnt to smallest variable.
7)Repeat the steps 4,5 and 6 till the comparision goes until the last element.

8)Stop.

Code goes here:

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Advertisment ad adsense adlogger