/** * */ /** *
A couple of methods to help you review for the second midterm.
*
These were discussed in class this week ...
* @author tomreinhardt
*
*/
public class TwoForReview {
/**
Example at the end of class on Wednesday 10 April.
* Make sure that you know how this method works. Also,
* make sure that you know how using StringBuilder
* impacts the amount of memory consumed by this method on
* large pieces of data.
* @return (String) word reversed.
*/
public static String nreverse(String word ) {
StringBuilder str = new StringBuilder();
int wordLength = word.length();
for( int i = 0 ; i < word.length(); i++ )
str.append( word.charAt( ( wordLength + i ) % wordLength ) );
return str.toString();
}
/**
*
This is kind of a kludge of several methods and ideas ... primary * here is the use of exceptions. * @param arrayOfCharacters * @return */ public static int intAt( int index, int[] arrayOfCharacters ) { int theInt = -1; try { theInt = arrayOfCharacters[ index ]; } catch( IndexOutOfBoundsException exception ) { /* Use the message from the real exception to make a better message that * your client will see: and then throw that as the result ... . */ throw new IndexOutOfBoundsException( exception.getMessage() + " from intAt method."); } return theInt; } }