题解 | #字符串分隔#

字符串分隔

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

import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String str = sc.nextLine();
			int strlength = str.length();
			if(strlength >= 8){//字符串长度大于等于8则每8位打印一次,取余部分用0补全8位;
				int a = str.length() / 8;
				int b = str.length() % 8;
				for (int i = 0; i < a; i++) {
					System.out.println(str.substring(0,8));
					str = str.substring(8,str.length());
				}
				if(b != 0){
					str = str + "00000000";
					System.out.println(str.substring(0,8));
				}
			}
			else{//字符串长度不满足8位直接用0补全
				str = str + "00000000";
				System.out.println(str.substring(0,8));
			}		
		}			
	}
}
全部评论

相关推荐

08-27 12:02
已编辑
南京外国语学校 网络安全
再来一遍:实则劝各位不要all in华子,不要相信华为hr
点赞 评论 收藏
分享
赛博小保安:不行你就找点东西继续干干直接等明年走社招吧,学历差的在秋招真的没戏。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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