時間限制:1秒 空間限制:32768K 熱度指數:94432 本題知識點: 字元串 算法知識視訊講解
題目描述
•連續輸入字元串,請按長度為8拆分每個字元串後輸出到新的字元串數組;
•長度不是8整數倍的字元串請在後面補數字0,空字元串不處理。
輸入描述:
連續輸入字元串(輸入2次,每個字元串長度小于100)
輸出描述:
輸出到長度為8的新字元串數組
示例1
輸入
abc
123456789
輸出
abc00000
12345678
90000000 import java.util.Scanner;
import java.util.*;
public class Main{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
while(sc.hasNext())
{
String str = new String(sc.nextLine());
if(str.length() %8 !=0)
{
str = str + "00000000";
}
while(str.length()>=8)
{
System.out.println(str.substring(0,8));
str = str.substring(8);
}
}
}
}