Java - Write code to truncate Last Char

Requirements

Write code to truncate Last Char

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String aString = "book2s.com";
        System.out.println(truncateLastChar(aString));
    }/*from w  w w  . j a  v  a2  s.  c  o  m*/

    public static String truncateLastChar(String aString) {
        return truncateLastNChar(aString, 1);
    }

    /**
     * truncate specified last N char
     * @param    aString the source string
     * @param    N   the number of char to truncate
     * @return   the truncated string
     */
    public static String truncateLastNChar(String aString, int N) {
        int length = aString.length();

        int indexOfTrancate = length - N;

        return aString.substring(0, indexOfTrancate);
    }
}