LargestElementInAnArray

LargestElementInAnArray - } public static int largest(int...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//Recursion: Largest Element in an Array / import java.io.*; i public class LargestElementInAnArray { public static void main(String[] args) { int[] intArray = {23, 43, 35, 38, 67, 12, 76, 10, 34, 8}; System.out.println("The largest element in intArray: " + largest(intArray, 0, intArray.length - 1));
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } public static int largest(int list, int lowerIndex, int upperIndex) { int max; if (lowerIndex == upperIndex) return list[lowerIndex]; else { max = largest(list, lowerIndex + 1, upperIndex); if (list[lowerIndex] >= max) return list[lowerIndex]; else return max; } } }...
View Full Document

This note was uploaded on 06/17/2011 for the course COMP 2301 taught by Professor Staff during the Spring '10 term at Kennesaw.

Ask a homework question - tutors are online