Skip to content

Instantly share code, notes, and snippets.

@jonathan-irvin
Last active August 29, 2015 14:19
Show Gist options
  • Save jonathan-irvin/2f9f0516c7c7e706812c to your computer and use it in GitHub Desktop.
Save jonathan-irvin/2f9f0516c7c7e706812c to your computer and use it in GitHub Desktop.
Int Range finder in java
import java.util.Scanner;
import java.util.Arrays;
public class IntRange {
public static double range(double[] numbers){
Arrays.sort(numbers);
double result = numbers[numbers.length-1] - numbers[0];
System.out.println("Highest Number: " + numbers[numbers.length-1]);
System.out.println("Lowest Number: " + numbers[0]);
return result;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
final int TOTAL_DOUBLES = 3;
double numbers[] = new double[TOTAL_DOUBLES];
for(int i=0;i<TOTAL_DOUBLES;i++){
System.out.print("Enter Number "+(i+1)+": ");
numbers[i] = input.nextDouble();
}
System.out.println("Range: "+range(numbers));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment