题解 | #字符串分隔#

字符串分隔

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

import java.util.Scanner;

public class Main{
    
     public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String s = sc.nextLine();
            splitStr(s);
        }
    }
    
    public static void splitStr(String str){
        String temp = "00000000";
        String result = "";
        for(int i = 0;i<=(str.length()-1)/8;i++){
            int s = i * 8;
            int e = (i+1) * 8;
            if(e>str.length()-1){
                String st = str.substring(s)+temp;
                result = st.substring(0,8);
            }else{
                result = str.substring(s,e);
            }
            System.out.println(result);
        }
    }
}
全部评论

相关推荐

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