题解 | #字符串分隔#
字符串分隔
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 的区别 String str = in.nextLine(); int length = str.length(); for(int i = 1; i < length; i ++ ){ String tmpstr; if(i * 8 < length){ tmpstr = str.substring((i - 1) * 8, i * 8); System.out.println(tmpstr); } else { String restStr = new String(); for(int j = length ; j < i*8 ; j ++ ){ restStr += Character.toString('0'); } tmpstr = str.substring((i - 1) * 8) + restStr; System.out.println(tmpstr); break; } } } }