class Test { public static void main(String[] args) { String str = "12345678"; String method = method(str); System.out.println("method = " + method); } private static String method(String s) { if (StringUtils.isBlank(s)) { return "00000000"; } int length = s.length(); if (length > 8) { return StringUtils.substring(s, 0, 8); } if (length == 8) { return s; } if (length < 8 && length > 0) { for (int i = 0; i <8-length ; i++) { s += "0"; } } return s; }
点赞

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务