Finding the minimum of an array from MAX_VALUE

FutureSwag

Currently I am trying to find the minimum value within the array. The user types in the array they want to create and then the program is supposed to find the minimum. I have tried using the max_int value to find he minimum but I haven't had any success. How can I find the minimum within the array?

public class Recursion {

    public static int findMin(int[] array, int index, int min) {
        int smallest = Integer.MAX_VALUE;
        for (int i = 0; i < array.length; i++) {
            if (array[i] < smallest) {
                smallest = array[i];
            }
            return findMin(array, index, min);
        }
        return smallest;
    }
}
HarryQ

From your description, you just need to find the min value in the array, so you don't need to use recursion for this problem. The following is an adaptation from your original code that does the job.

public static int findMin(int[] array) {
    int smallest = Integer.MAX_VALUE;
    for (int i = 0; i < array.length; i++) {
        if (array[i] < smallest) {
            smallest = array[i];
        }
    }
    return smallest;
}

If you can use the Stream interface, you can use a one liner for this problem.

 public static int findMin(int[] array) {
  return Arrays.stream(array).min().getAsInt();
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Finding a minimum and maximum value in an array

From Dev

library header for finding 2 minimum value from array in java

From Dev

Finding the minimum value of int numbers in an array (Java)

From Dev

Finding minimum in an array

From Dev

Finding the minimum positive value

From Dev

Finding minimum value in dictionary

From Dev

Finding minimum value in a collection

From Dev

finding the minimum value of pair of numbers in array C Lang

From Dev

Finding a minimum value in each column of 8*720 array?

From Dev

Finding the minimum of a python data array

From Dev

Finding max value in array with increasing values from either side of an index

From Dev

Finding minimum value for each row from 2 matrix R

From Dev

Finding minimum value according to a comparator

From Dev

Java, Finding Kth largest value from the array

From Dev

Finding smallest value from array in java

From Dev

Finding the index of a value from a random dimensional array

From Dev

Finding indexof value starting from the end of an array

From Dev

Finding Minimum Distance Between Words in An Array

From Dev

Finding the minimum in an array (Intel8086)

From Dev

write a function finding maximum/minimum of array in javascript

From Dev

finding minimum element of array using recursion

From Dev

Finding maximum and minimum of an array in a single recursive function

From Dev

Finding the minimum sum within an array of numbers

From Dev

Finding maximum and minimum Inside array of objects

From Dev

Finding the minimum in an array (Intel8086)

From Dev

Finding the minimum sum within an array of numbers

From Dev

Java – Finding minimum and maximum values in an array

From Dev

Finding minimum and maximum date in an complex json array

From Dev

Last element of array changes when finding minimum

Related Related

  1. 1

    Finding a minimum and maximum value in an array

  2. 2

    library header for finding 2 minimum value from array in java

  3. 3

    Finding the minimum value of int numbers in an array (Java)

  4. 4

    Finding minimum in an array

  5. 5

    Finding the minimum positive value

  6. 6

    Finding minimum value in dictionary

  7. 7

    Finding minimum value in a collection

  8. 8

    finding the minimum value of pair of numbers in array C Lang

  9. 9

    Finding a minimum value in each column of 8*720 array?

  10. 10

    Finding the minimum of a python data array

  11. 11

    Finding max value in array with increasing values from either side of an index

  12. 12

    Finding minimum value for each row from 2 matrix R

  13. 13

    Finding minimum value according to a comparator

  14. 14

    Java, Finding Kth largest value from the array

  15. 15

    Finding smallest value from array in java

  16. 16

    Finding the index of a value from a random dimensional array

  17. 17

    Finding indexof value starting from the end of an array

  18. 18

    Finding Minimum Distance Between Words in An Array

  19. 19

    Finding the minimum in an array (Intel8086)

  20. 20

    write a function finding maximum/minimum of array in javascript

  21. 21

    finding minimum element of array using recursion

  22. 22

    Finding maximum and minimum of an array in a single recursive function

  23. 23

    Finding the minimum sum within an array of numbers

  24. 24

    Finding maximum and minimum Inside array of objects

  25. 25

    Finding the minimum in an array (Intel8086)

  26. 26

    Finding the minimum sum within an array of numbers

  27. 27

    Java – Finding minimum and maximum values in an array

  28. 28

    Finding minimum and maximum date in an complex json array

  29. 29

    Last element of array changes when finding minimum

HotTag

Archive