Java - Write code to Return one character from input string.

Requirements

Write code to Return one character from input string.

Demo

/*
 * Static String formatting and query routines.
 * Copyright (C) 2001-2005 Stephen Ostermiller
 * http://ostermiller.org/contact.pl?regarding=Java+Utilities
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version./*from   w  ww .  j  av  a 2 s. c om*/
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * See COPYING.TXT for details.
 */
public class Main{
    public static void main(String[] argv){
        String value = "book2s.com";
        System.out.println(getValidatedInput(value));
    }
    /**
     * Returns one character from input string.
     *
     * @param value input string
     * @return first character
     * @throws InputValidationException thrown if no character was extracted from value.
     */
    public static char getValidatedInput(String value)
            throws InputValidationException {
        char firstChar = getFirstCharFromInput(value);
        if (firstChar == 0) {
            throw new InputValidationException(
                    "You must specify one-character values for advanced CSV settings.");
        }
        return firstChar;
    }
    /**
     * TODO docs
     *
     * @param input input string
     * @return the first char of the input string
     */
    public static char getFirstCharFromInput(String input) {
        if (input.length() == 1) {
            return input.charAt(0);
        } else if (input.equals("\\n")) {
            return '\n';
        } else if (input.equals("\\t")) {
            return '\t';
        } else {
            return 0;
        }
    }
}