字符串分隔(java)

来源:互联网 发布:墨索里尼 黑手党 知乎 编辑:IT博客网 时间:2018/12/10 03:50
import java.util.*;public class SplitString {public static void main(String[] args) {Scanner scan = new Scanner(System.in);int num = scan.nextInt();List<String> strList = new LinkedList<String>();while (num != -1) {strList.add(scan.nextLine());num--;}Iterator<String> itor = strList.iterator();while (itor.hasNext()) {String str = itor.next();splitStr(str);}}  private static void splitStr(String str) {if(str.length() <= 8){if(str.length()==0)return;else{int len = str.length();for (int i = 0; i < 8-len; i++) {str = str + "0";}print(str);}}else{String str1 = str.substring(0, 8);print(str1);String str2 = str.substring(8);splitStr(str2);}}private static void print(String str) {System.out.println(str);}}

1、String.subString(int start,int end)的用法。

2、递归调用截取字符串函数splitString

0 0