- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find Min/Max numbers in a java array?
You can find the minimum and maximum values of an array using for loops −
Example
public class MinAndMax { public int max(int [] array) { int max = 0; for(int i=0; i<array.length; i++ ) { if(array[i]>max) { max = array[i]; } } return max; } public int min(int [] array) { int min = array[0]; for(int i=0; i<array.length; i++ ) { if(array[i]<min) { min = array[i]; } } return min; } public static void main(String args[]) { int[] myArray = {23, 92, 56, 39, 93}; MinAndMax m = new MinAndMax(); System.out.println("Maximum value in the array is::"+m.max(myArray)); System.out.println("Minimum value in the array is::"+m.min(myArray)); } }
Output
Maximum value in the array is ::93 Minimum value in the array is ::23
- Related Articles
- Find max and min values in array of primitives using Java
- Find max and min values in an array of primitives using Java
- How to find the min/max element of an Array in JavaScript?
- Minimum removals from array to make max – min
- Min-Max Range Queries in Array in C++
- Average of array excluding min max JavaScript
- JavaScript: How to Find Min/Max Values Without Math Functions?
- Min and max values of an array in MongoDB?
- Find Min-Max in heterogeneous list in Python
- Java Program to generate random number array within a range and get min and max value
- Min-Max Heaps
- How to create a horizontal slider with custom min, max, and initial value in Java
- Sort array based on min and max date in JavaScript?
- Get max and min values of an array in Arduino
- How to use min and max attributes in HTML?

Advertisements