Java Program to Find Largest Number in Array Using Recursion

Here you will get java program to find largest number in array using recursion.

public class LargestNumber {
	public static void main(String args[]) {
		int a[] = {5, 12, 10, 6, 15};
		
		System.out.println("Given Array:  ");
		for(int i = 0; i < a.length; ++i)
			System.out.print(a[i] + " ");
		
		System.out.println("\n\nLargest Number is " + findLargest(a, a.length-1));
	}
	
	public static int findLargest(int[] a, int index) {
	    if (index > 0) {
	        return Math.max(a[index], findLargest(a, index-1));
	    } else {
	        return a[0];
	    }
	}
}

Output

Given Array:
5 12 10 6 15

Largest Number is 15

Comment below if you have any queries regarding above program.

Leave a Comment

Your email address will not be published. Required fields are marked *