题解 | #字符串分隔#

字符串分隔

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

Java实现:
1、题目要求输入字符串长度小于等于100;
2、判断输入为空,直接打印"00000000";
3、判断字符串长度是否能整除8,不能则补"0";
4、使用substring输出指定的字符串长度;
import java.util.*;
public class Main {
    public static void main(String[] args) throws IOException {
        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int len = str.length();
            if(len <= 100){
                if(len==0){
                    System.out.println("00000000");
                }
                if(len%8 != 0){
                for(int i=0;i<8-len%8;i++){
                    str += "0";
                    }
                }
                for(int j=0;j<len;j += 8){
                    System.out.println(str.substring(j,j+8));
                }  
            
        }else{
                System.out.println("输入字符串的长度应小于等于100"+str);
            }
    }
}


#小白的技术进阶日记#
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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