Java || Snippet – How To Find The Highest & Lowest Numbers Contained In An Integer Array

Print Friendly, PDF & Email

This page will consist of a simple demonstration for finding the highest and lowest numbers contained in an integer array.


Integer Arrays
For Loops
Custom Setw/Setfill In Java

Finding the highest/lowest values in an array can be found in one or two ways. The first way would be via a sort, which would obviously render the highest/lowest numbers contained in the array because the values would be sorted in order from highest to lowest. But a sort may not always be practical, especially when you want to keep the array values in the same order that they originally came in.

The second method of finding the highest/lowest values is by traversing through the array, literally checking each value it contains one by one to determine if the current number which is being compared truly is a target value or not. That method will be displayed below.

The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

Once compiled, you should get this as your output

Welcome to My Programming Notes' Java Program.

Original array values:
36 35 46 86 86 58 44 38 79 52 27 78 65 79
These are the highest and lowest array values:
Highest: 86
Lowest: 27

Was this article helpful?
👍 YesNo

Leave a Reply