 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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
Advertisements
 