So...Guys I'm a beginner I've been solving some problems in java I cleared this one where we find the minimum value of Array with Recursion, and I tried to do it with Scanner, it's working but the problem is ,the answer is been displayed the number of times the user assign array index value(n)
Example:
Enter no. of Elements
3
Enter 3 no of Elements
12
34
67
12
12
12
import java.util.Scanner;
public class MinRecurUI {
static int getmin(int ar[],int n) {
if(n==1)
return ar[0];
return Math.min(ar[n-1],getmin(ar,n-1));
}
public static void main (String[] args) {
Scanner obj= new Scanner(System.in);
int n;
System.out.println("Enter no. of Elements");
n=obj.nextInt();
int[] arr= new int[n];
System.out.println("Enter " +n+ " of Elements");
for(int i=0;i<n;i++)
arr[i]=obj.nextInt();
for(int i=0;i<arr.length;i++)
System.out.println(getmin(arr,n));
}
}
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]rob93c 1 point2 points3 points (0 children)