In: Computer Science
Write a recursive method to find the smallest int in an unsorted array of numbers.
int[] findMin = { 0, 1, 1, 2, 3, 5, 8, -42, 13, 21, 34, 55, 89 };
System.out.printf("Array Min: %d\n", arrayMin(findMin, 0)
public static int arrayMin(int[] data, int position) { ??? }
everything I've tried doesn't return the -42 like it should, somehow I think I end up returning a count of the search or something like that and I'm not sure where I'm going wrong. Thanks for the help.
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int[] findMin= { 0, 1, 1, 2, 3, 5,
8, -42, 13, 21, 34, 55, 89 };
System.out.printf("Array Min:
%d\n", arrayMin(findMin, 0));
}
public static int arrayMin(int[] data, int
position)
{
int n = data.length;//to know the length of the
array.
int i,min;
min = data[position];
for(i=0;i<n;i++)
{
if(min>data[i])
{
min=data[i];
arrayMin(data,i++);
}
}
return min;
}
}

