题解 | #字符串分隔#

字符串分隔

http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        ArrayList<String> strs = new ArrayList<String>();
        while (in.hasNextLine()) { 
            String str = fillStr(in.nextLine().trim());
            int num = str.length()/8 ;
            for(int i = 0;i < num; i++){
                  strs.add(str.substring((i*8),(i*8) + 8));
            } 
        }
        for(String str : strs){
            System.out.println(str);
        }
    }
    public static String fillStr(String str){
        StringBuffer sb = new StringBuffer(str);
        int count = sb.length()%8;
        if(count > 0){
            for(int i = 0;i < 8 - count;i++ ){
                sb.append("0");
            }
        }
        return sb.toString();
    }
}

全部评论

相关推荐

点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务