public class Main
{
{
String s1
= "Remove Last CharacterY"; String s2
= "Remove Last Character2"; System.
out.
println("After removing s1==" + removeLastChar
(s1
) + "=="); System.
out.
println("After removing s2==" + removeLastChar
(s2
) + "=="); }
return removeLastChars(str, 1);
}
public static String removeLastChars
(String str,
int chars
) { return str.substring(0, str.length() - chars);
}
}
cHVibGljIGNsYXNzIE1haW4KewogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBqYXZhLmxhbmcuRXhjZXB0aW9uCiAgICB7CiAgICAgICAgU3RyaW5nIHMxID0gIlJlbW92ZSBMYXN0IENoYXJhY3RlclkiOwogICAgICAgIFN0cmluZyBzMiA9ICJSZW1vdmUgTGFzdCBDaGFyYWN0ZXIyIjsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIkFmdGVyIHJlbW92aW5nIHMxPT0iICsgcmVtb3ZlTGFzdENoYXIoczEpICsgIj09Iik7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJBZnRlciByZW1vdmluZyBzMj09IiArIHJlbW92ZUxhc3RDaGFyKHMyKSArICI9PSIpOwogICAgICAgIH0KICAgIAogICAgcHVibGljIHN0YXRpYyBTdHJpbmcgcmVtb3ZlTGFzdENoYXIoU3RyaW5nIHN0cikgewogICAgICAgIHJldHVybiByZW1vdmVMYXN0Q2hhcnMoc3RyLCAxKTsKICAgIH0KCiAgICBwdWJsaWMgc3RhdGljIFN0cmluZyByZW1vdmVMYXN0Q2hhcnMoU3RyaW5nIHN0ciwgaW50IGNoYXJzKSB7CiAgICAgICAgcmV0dXJuIHN0ci5zdWJzdHJpbmcoMCwgc3RyLmxlbmd0aCgpIC0gY2hhcnMpOwogICAgfQp9