美文网首页
524.Left Pad

524.Left Pad

作者: 博瑜 | 来源:发表于2017-07-22 16:51 被阅读0次
public class StringUtils {
/**
 * @param originalStr the string we want to append to with spaces
 * @param size the target length of the string
 * @return a string
 */
static public String leftPad(String originalStr, int size) {
    // Write your code here
     return leftPad( originalStr,  size, ' ');
}

/**
 * @param originalStr the string we want to append to
 * @param size the target length of the string
 * @param padChar the character to pad to the left side of the string
 * @return a string
 */
static public String leftPad(String originalStr, int size, char padChar) {
    // Write your code here
    int length = originalStr.length();
    StringBuilder sb = new StringBuilder();
    int addLength = size - length;
    for (int i = 0; i < addLength; i++) {
        sb.append(padChar);
    }
    sb.append(originalStr);
    return sb.toString();
}
}

相关文章

  • 524.Left Pad

  • np.pad()

    pad()函数 方法参数:pad(array, pad_width, mode, **kwargs)方法返回:填充...

  • pad

    #试试pad写作怎么样 记得记得姐姐

  • 什么是培训学校展销pad?

    这些您可能见过? Pad点餐系统 餐厅➕Pad平板➕点餐软件 例如俏江南,海底捞 Pad智能移动办卡终端 pad...

  • php7 DES加密 兼容php5.3以上所有版本

    加密原方案:pad = str) % str .= str_repeat(chr(pad);key, ret = ...

  • 卷积np.pad()函数快速理解

    函数结构 pad(array, pad_width, mode, **kwargs) 参数意思 array :你要...

  • PAD测试

    这是PAD生成文章

  • pad包

    给健哥做了个pad包,棉麻的,有点文艺小清新的赶脚! 包包用了表布,里布还有内衬,拿起来软软的,萌萌的! 最后,可...

  • pad or 电脑

    现在许多任务的完成都不是必须使用电脑才能完成,用手机或者是pad一样也可以很好的完成,比如写文件,发邮件,我们只需...

  • pad man

    电影印度合伙人给了我不少启发: 1、路是一步一步走出来的,想法也是一步一步变现的,要敢于尝试,敢于行动,在试错中成...

网友评论

      本文标题:524.Left Pad

      本文链接:https://www.haomeiwen.com/subject/drpukxtx.html