题解 | #字符串分隔#

字符串分隔

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        // 注意 while 处理多个 case
        String temp = in.next();
        char[] tempChar = temp.toCharArray();
        int count = tempChar.length;
        int counti = count/8;
        int countj = count%8;
        int countTempStart = 0;
        int countTempEnd = 8;
        for(int i=0;i<counti;i++){
            StringBuffer tempString = new StringBuffer("");
            for(int j=countTempStart;j<countTempEnd;j++){
                tempString.append(tempChar[j]);
            }
            countTempStart = countTempEnd;
            countTempEnd = countTempStart+8;
            System.out.println(tempString);
        }
        if(countj > 0){
            StringBuffer tempString = new StringBuffer("");
            for(int i=countTempStart;i<tempChar.length;i++){
                tempString.append(tempChar[i]);
            }
            for(int j=0;j<(8-countj);j++){
                tempString.append("0");
            }
            System.out.println(tempString);
        }
    }
}

全部评论

相关推荐

10-11 14:44
济南大学 Java
点赞 评论 收藏
分享
在看牛客的社畜很积极:身高体重那一行信息去掉,学校那一行的信息放上面,找半天都没找到你是哪个学校什么专业的
点赞 评论 收藏
分享
09-30 15:27
已编辑
成都工业学院 企业文化
Morpheus_:候选人:还需要测验武力值?
投递腾讯等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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