题解 | #字符串分隔#
字符串分隔
http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { String str = scanner.nextLine(); int b = str.length() / 8; int a = str.length() % 8; String c = "00000000"; if (b > 0) { for (int i = 0; i < b; i++) { System.out.println(str.substring(i * 8, 8 * (i + 1))); } if (a != 0) { System.out.println(str.substring(str.length() - a, str.length()) + c.substring(a, 8)); } }else { System.out.println(str.substring(str.length() - a, str.length()) + c.substring(a, 8)); } } } }