Problem Statement
A useful statistic in many applications is the range of a group of numbers. The range is defined as the difference between the largest element in the group, and the smallest element in the group. For example, the range of {1,5,7,3,8} is 7, since the difference between 1 and 8 is 7.
Your task is to write a class Statistics, with a method getRange, which takes a int[], numbers, and returns the range of the elements of numbers.
Definition
- Class:
- Statistics
- Method:
- getRange
- Parameters:
- int[]
- Returns:
- int
- Method signature:
- int getRange(int[] numbers)
- (be sure your method is public)
Constraints
- numbers contains between 2 and 50 elements, inclusive.
- Each element of numbers is between -1,000,000 and 1,000,000, inclusive.
Examples
{1,5,7,8,3}Returns: 7
This is the example mentioned in the problem statement.{1,2,3,2,1}Returns: 2
The range is 3 - 1 = 2.{1000,-1000,0}Returns: 2000
{-1000000,1000000}Returns: 2000000
{45,45,45,45,45}Returns: 0