Advertisement
Guest User

a

a guest
Feb 6th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Tang7 {
  3.  
  4. public static void main(String[] args) {
  5. //This program prompts the user to enter 10
  6. //number and return the minimum value
  7. Scanner in = new Scanner(System.in);
  8. //Ask for user input
  9. System.out.print("Enter ten numbers: ");
  10. //10 input will be entered
  11. double[] numbers = new double[10];
  12. int i;
  13.  
  14. //for i equal to 0, and i is less than
  15. //number's length (10), i increment
  16. //allow user to enter 10 inputs
  17. for (i = 0; i < numbers.length; i++) {
  18. numbers[i] = in.nextDouble();
  19. }
  20. in.close();
  21. //print out result + create a static
  22. System.out.println("The minimum number is: " + min(numbers));
  23.  
  24. }
  25.  
  26. private static double min(double[] array) {
  27. double min = array[0];
  28.  
  29. //for i equal to 1 and i is less than
  30. //array's length, i increment
  31. for (int i = 1; i < array.length; i++) {
  32. //if min is longer than array
  33. //min become equal to array
  34. if (min > array[i]){
  35. min = array[i];
  36. }
  37. }
  38. return min;
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement