Recursive Program to find Largest Element of the array in Java
Login/Signup to comment
2 comments on “Recursive Program to find Largest Element of the array in Java”
×
30+ Companies are Hiring
Get Hiring Updates right in your inbox from PrepInsta
//recrusive way in simpler way
public class Main
{
public static void main(String[] args) {
recurse obj=new recurse();
int arr[]={100,4,200,9,10};
System.out.println(obj.largest(arr,4));
}
}
class recurse{
int big=0;
public int largest(int arr[],int n){
if(nbig)
big=arr[n];
return largest(arr,n – 1);
}
}
public static int maxElement(int[] arr, int i, int max){
if (i==arr.length){
return max;
}
if (max<arr[i]){
max = arr[i];
}
return maxElement(arr,i+1,max);
}