import java.util.*; class UseArrayListsRec3 // Demonstrates a method which returns the largest integer in an ArrayList. // The method is implemented using recursion which is not tail recursion, // but treating ArrayLists like arrays. { public static void main(String[] args) throws Exception { Scanner input = new Scanner(System.in); System.out.println("Enter some numbers (all on one line, separated by spaces):"); String line = input.nextLine(); String[] numbers = line.split(" +"); ArrayList a = new ArrayList(); for(int i=0; i a) { return biggest(a,0); } private static int biggest(ArrayList a,int from) { int n=a.get(from); if(from==a.size()-1) return n; else { int biggestOfRest = biggest(a,from+1); if(n>biggestOfRest) return n; else return biggestOfRest; } } }