题目描述

•连续输入字符串,请按长度为8拆分每个字符串后输出到新的字符串数组;
•长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。

输入描述:连续输入字符串(输入2次,每个字符串长度小于100)

输出描述:输出到长度为8的新字符串数组

输入例子:

abc

123456789

输出例子:

abc00000

12345678

90000000

import java.util.Scanner;

public class Split812 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext())
        {
            String string = scanner.nextLine();
            Split(string);
        }
    }

    private static void Split(String string) {
        while(string.length() >= 8)
        {
            System.out.println(string.substring(0,8));
            string = string.substring(8);
        }
        if(string.length() > 0 && string.length() < 8)
        {
            string += "00000000";
            System.out.println(string.substring(0,8));
        }
    }

}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2021-12-23
  • 2022-01-07
  • 2021-08-07
  • 2021-05-30
  • 2022-01-24
猜你喜欢
  • 2021-10-29
  • 2022-12-23
  • 2021-07-18
  • 2021-06-18
相关资源
相似解决方案