# Java program to find differences between minimum and maximum numbers in an array

In this java program, we are going to learn how to find the smallest (minimum), largest (maximum) numbers from an array and also find their difference?
Submitted by IncludeHelp, on November 30, 2017

Given an array, we have to find the minimum, maximum numbers and their difference of them using java program.

Example:

```    Input:  10 20 30 40 50
Minimum number: 10
Maximum number: 50
Differences of minim and maximum number: (50-10) = 40
```

## Program to find difference of minimum and maximum numbers of array in java

```import java.util.Scanner;

class MinMaxInArray {
//method to get maximum number
//from array elements
int getMax(int[] inputArray) {
int maxValue = inputArray;

for (int i = 1; i < inputArray.length; i++) {
if (inputArray[i] > maxValue) {
maxValue = inputArray[i];
}
}
return maxValue;
}

//method to get minimum number from array elements
int getMin(int[] inputArray) {
int minValue = inputArray;

for (int i = 1; i < inputArray.length; i++) {
if (inputArray[i] < minValue) {
minValue = inputArray[i];
}
}
return minValue;
}
}

public class ExArrayDifference {
public static void main(String[] args) {
int n;

// create object of scanner.
Scanner sc = new Scanner(System.in);

// you have to enter number here.
System.out.print("Enter number of elements you wants to enter :");

// read entered number and store it in "n".
n = sc.nextInt();

int arr[] = new int[n];

for (int i = 0; i < arr.length; i++) {
System.out.print("Enter [" + (i + 1) + "] element :");
arr[i] = sc.nextInt();
}

MinMaxInArray mm = new MinMaxInArray();

// print max , min , difference of array elements.
System.out.println("Maximum value is :" + mm.getMax(arr));
System.out.println("Minimum value is :" + mm.getMin(arr));
int Difference = mm.getMax(arr) - mm.getMin(arr);
System.out.print("Difference between Minnimum and Maximum in array is : " + Difference);
}
}
```

Output

```    Enter number of elements you wants to enter :10
Enter  element :25
Enter  element :36
Enter  element :74
Enter  element :85
Enter  element :964
Enter  element :215
Enter  element :36
Enter  element :58
Enter  element :98
Enter  element :123
Maximum value is :964
Minimum value is :25
Difference between Minnimum and Maximum in array is : 939
```