Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Tang7 {
- public static void main(String[] args) {
- //This program prompts the user to enter 10
- //number and return the minimum value
- Scanner in = new Scanner(System.in);
- //Ask for user input
- System.out.print("Enter ten numbers: ");
- //10 input will be entered
- double[] numbers = new double[10];
- int i;
- //for i equal to 0, and i is less than
- //number's length (10), i increment
- //allow user to enter 10 inputs
- for (i = 0; i < numbers.length; i++) {
- numbers[i] = in.nextDouble();
- }
- in.close();
- //print out result + create a static
- System.out.println("The minimum number is: " + min(numbers));
- }
- private static double min(double[] array) {
- double min = array[0];
- //for i equal to 1 and i is less than
- //array's length, i increment
- for (int i = 1; i < array.length; i++) {
- //if min is longer than array
- //min become equal to array
- if (min > array[i]){
- min = array[i];
- }
- }
- return min;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement