All pastes #356844 Raw Edit

ShadeS

public java v1 · immutable
·published 2007-02-15 09:11 UTC
rendered paste body
Programming Assignment 2: Recursion ExercisesThis program is to be submitted via Blackboard by 10:00 p.m. Monday Feb. 12; I'm making the date late just to allow you to schedule your time.  It should in fact take you only a few hours tops, and the next assignment will be due a few days later and will be much longer.  This assignment will count for less than a full programming assignment. Write a class called recursiveUtilities with the following public static methods:1. A recursive method called minArray that finds the minimum value in an array of int values without using any loops. Input: one array of ints.  Return type: int .  (Based on text C-3.15)2. A recursive method called isPalindrome that takes a character String and returns a boolean telling whether the input string is a palindrome. (Based on text C-3.19)3. A recursive method called reverse that takes a character String and returns a String that is the reverse of the original input. (Based on text C-3.18)Note that in some or all of these cases the public static method may simply be a short wrapper that calls another method that is recursive but takes a different number of parameters.public class recursiveUtilities {	public static void main(String[] args) {		int[] TestArray = {30, 8, 31, 400, 3, 630, 70, 4, 7, 20};		recursiveUtilities h = new recursiveUtilities();	    //int smallest = h.minArray(TestArray, Integer.MAX_VALUE, 0);	   // System.out.println(smallest);		char[] palindromeCheck = {'a', 'm', 'o', 'm', 'a'};		String[] charString = {"Testing"};		//boolean check = h.		System.out.println("Reverse this: " + charString + swap0rama(charString, 0, charString.length-1));		System.out.println("isPalindrome? . . . " + isPalindrome(palindromeCheck, 0, palindromeCheck.length-1));	}	public static int minArray(int[] array, int currSmallest, int stopIndex){ //left to right		int localCurrSmallest = Integer.MAX_VALUE;			if (stopIndex == array.length-1){  //if at end of array, done			return array[stopIndex];	    }	    else{	    	if (array[stopIndex] <  minArray(array, currSmallest, stopIndex+1)){	    		localCurrSmallest = array[stopIndex];            }            else{	            localCurrSmallest = minArray(array, currSmallest, stopIndex+1);	            }	    }		return localCurrSmallest;	}		public static boolean isPalindrome(char[] array, int startIndex, int endIndex){				if (array[startIndex]==array[endIndex] && endIndex == 1)			return true;				if (array[startIndex]!=array[endIndex] || endIndex <= 1){			System.out.println("false.!!.");			return false;		}		else{					return isPalindrome(array, startIndex+1, endIndex-1);						}	} 	public static String swap0rama(String StringArray, int startIndex, int endIndex){		//base case: end is zero, thus all was swapped		if (endIndex == 0){			return backWard;		}		if (endIndex > 0){ //if the end isn't reached, copy the value			String backWard;			backWard.concat(StringArray.valueOf(endIndex));		}		else		return swap0rama(StringArray, startIndex+1, endIndex-1);	}}