题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
import java.util.Locale; import java.util.Scanner; public class Main { public static void main(String[] args) { //对输入的字符串进行按8进行换行 //每8个字符一行,不足8的补0处理 Scanner sc = new Scanner(System.in); String str = sc.nextLine(); int lenght = str.length(); // System.out.println(lenght); int count = 0; //实现每8个数据就换行! for (int i = 0; i < str.length(); i++) { if (count == 8) { count = 0; System.out.println(); } System.out.print(str.charAt(i)); count++; } // System.out.println(); // System.out.print(count); //进行补0 for (int i = 0; i < 8 - count; i++) { System.out.print(0); } } }