题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 // 注意 while 处理多个 case String temp = in.next(); char[] tempChar = temp.toCharArray(); int count = tempChar.length; int counti = count/8; int countj = count%8; int countTempStart = 0; int countTempEnd = 8; for(int i=0;i<counti;i++){ StringBuffer tempString = new StringBuffer(""); for(int j=countTempStart;j<countTempEnd;j++){ tempString.append(tempChar[j]); } countTempStart = countTempEnd; countTempEnd = countTempStart+8; System.out.println(tempString); } if(countj > 0){ StringBuffer tempString = new StringBuffer(""); for(int i=countTempStart;i<tempChar.length;i++){ tempString.append(tempChar[i]); } for(int j=0;j<(8-countj);j++){ tempString.append("0"); } System.out.println(tempString); } } }