Find largest and smallest number in the given Array

By | December 7, 2018

This post of  To find largest and smallest number in the given Array is about writing a Java program to find the largest and the smallest number in the given input Array or it can also be rephrased as – Find the maximum and minimum number in the given array.

Condition here is that you should not be using any inbuilt Java classes (i.e. Arrays.sort) or any existing data structure.

You may also like –

Java Program to find duplicate elements in an Array

In this logic We have two variables for maximum and minimum number, initially assign the element at the first index of the array to both the variables.

Then loop or iterate the array and compare each array element with the max number if max number is less than the array element then assign array element to the max number.

If max number is greater than the array element then we have to check if minimum number is greater than the array element, if yes then assign array element to the minimum number.

Output of Above Example:

That’s all about topic How to find largest and smallest number in the given input Array. If you have any doubts or any suggestions to make please drop a comment.

Leave a Reply

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