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:

You May Also Like:

How to swap two numbers with or without temporary variable in java
Java Program to Swap two numbers using Bitwise XOR Operator?
How to reverse a number in Java
How to check Armstrong number java program
Java program to find factorial of a number
Java Program to Calculate the Power of a Number
Check whether a number is prime or not
Java Program to displaying prime numbers
Fibonacci series using iterative and recursive approach java program
Java program to Remove Duplicate Elements From an Array
Find common elements between two Arrays
Find largest and smallest number in the given Array
Java Program to find duplicate elements in an Array
Count number of words in a string in java
How would you check if a number is even or odd using bit wise operator in Java?
How can you check if the given number is power of 2?
How to check if String is number in java ?

That’s all about the topic How to find the 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.