题解 | #字符串分隔#
字符串分隔
http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); String line=sc.nextLine(); int len=line.length(); int k=line.length()/8; int i=0; for(;i<k;i++){ System.out.println(line.substring(i*8,i*8+8)); } int last=line.length()%8; if(last==0) return; char[] chars=new char[8]; Arrays.fill(chars,'0'); for(int j=i*8;j<i*8+last;j++){ chars[j-i*8]=line.charAt(j); } System.out.println(new String(chars)); } }