package text;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
int length = 0;
String s = "";
length = new Scanner(System.in).nextInt();
String[] s1 = split(s, length);
for (int i = 0; i < s1.length; i++) {
System.out.print(s1[i] + " ");
}
}
private static String[] split(String str, int length) {
int n = (str.length() + length - 1) / length;
System.out.println("n=" + n);
String[] s = new String[n];
for (int i = 0; i < n; i++) {
if (i < n - 1) {
s[i] = str.substring(i * length, (i + 1) * length);
} else {
s[i] = str.substring(i * length);
}
}
return s;
}
}
给出一个字符串和长度,给字符串进行分隔
最新推荐文章于 2020-03-16 14:30:21 发布