字符串分割
来源:互联网 发布:资源数据库微博 编辑:程序博客网 时间:2024/06/05 19:55
package oj.test;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;
public class Demo2 {
/**
* 字符串分割
* 连续输入字符串(输出次数为N,字符串长度小于100),请按长度为8拆分每个字符串后输出到新的字符串数组,长度
* 不是8整数倍的字符串请在后面补数字0,空字符串不处理。首先输入一个整数,为要输入的字符串个数。
* 例如:
* 输入:2
* abc
* 12345789
* 输出:abc00000
* 12345678
* 90000000
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
LinkedList<String> list = new LinkedList<String>();
while(num!=-1){
list.add(sc.nextLine());
num--;
}
Iterator<String> it = list.iterator();
while(it.hasNext()){
//sop(it.next());
String str = it.next();
cut(str);
}
}
private static void cut(String str){
if(str.length()==0){
}else
if(str.length()<=8 ){
int l = str.length();
for(int i=0;i<8-l;i++){
str=str+"0";
}
sop(str);
}
else if(str.length()>8)
{
String temp = str.substring(0, 8);
sop(temp);
cut(str.substring(8));
}
}
public static void sop(Object obj){
System.out.println(obj);
}
}
- 分割字符串
- 分割字符串
- 分割字符串
- 分割字符串
- 分割字符串
- 字符串分割
- 字符串分割
- 分割字符串
- 字符串分割
- 字符串分割
- 分割字符串
- 分割字符串
- 分割字符串
- 字符串分割
- 分割字符串
- 字符串分割
- 字符串分割
- 分割字符串
- android.content.Context 含义及使用
- 个人简历
- Step-By-Step Plan For A Career Change
- HDU1160 Cantor
- 登录超时
- 字符串分割
- zoj 2112 Dynamic Rankings/树套树
- JAVA 第四次实验
- 算法效率分析框架
- 动态规划~概念理解
- AngularJs与Java Web服务器交互
- LVM学习
- 例题3-3
- Redis集群方案,Codis安装测试