Last active
August 29, 2015 14:19
-
-
Save jonathan-irvin/2f9f0516c7c7e706812c to your computer and use it in GitHub Desktop.
Int Range finder in java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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