从键盘输入一串数字字符串,将串从数字不连续的位置断开,打印输出多个连续的串。
例如:输入:12345234568923456789
输出:12345
23456
89
23456789
import java.util.Scanner;
public class Test {
public static void main(String[] agsr) {
System.out.print("请输入一串数字:");
Scanner sc = new Scanner(System.in);
String scs = sc.next();
String s = scs;
String t = "1";
for (int i = 1; i < s.length(); i++) {
if (s.charAt(i) == s.charAt(i - 1) + 1) {
t += s.charAt(i);
} else {
System.out.println(t);
t = ""+s.charAt(i);
}
}
System.out.println(t);
}
}
运行截图: