在一行上输入一个长度
,由小写字母和数字构成的字符串
。
输出若干行,每行输出
个字符,代表按题意书写的结果。
hellonowcoder
hellonow coder000
在这个样例中,字符串长度为
,因此需要在第二行末尾补充
个
。
0
00000000
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str = in.nextLine();
// str = StringUtils.rightPad(str, str.length() + (8 - str.length() % 8), '0');
str = str + (str.length() % 8 == 0 ? "" : "00000000".substring(0,8 - str.length() % 8));
for(int i = 0; i < str.length() / 8; i++) {
System.out.println(str.substring(i * 8, i * 8 + 8));
}
}
} public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); StringBuilder builder = new StringBuilder(s); if (builder.length() >=0 && builder.length() <=100) { StringBuilder b1 = new StringBuilder(); for (int i=0 ; i<builder.length(); i++) { b1.append(builder.charAt(i)); if ((i + 1) % 8 == 0) { System.out.println(b1.toString()); b1.setLength(0); } } if (b1.length() > 0) { while (b1.length() < 8) { b1.append(0); } System.out.println(b1.toString()); } } } }
import java.util.Scanner;
public class Main {
private static int LENGTH=8;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
String str = sc.nextLine();
String output;
if (str.length()<1 || str.length() >100) return;//
for (int i = 0; i<str.length(); i+=LENGTH) {//按照8个一次遍历
if(i+LENGTH<str.length()){//未超出长度,直接截取8位输出
output= str.substring(i,i+LENGTH);
System.out.println(output);
}else{//超出长度补齐8位
output= str.substring(i,str.length());
System.out.print(output);
for (int j = output.length();j<8;j++){
System.out.print("0");
}
}
}
sc.close();
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.nextLine();
for (int i = 0; i < s.length()/8; i++) {
System.out.println(s.substring(i * 8, 8 * (i + 1)));
}
if (s.length() % 8 != 0) {
System.out.print(s.substring(s.length()/8 *8, s.length()));
for (int i = 0; i < 8 - s.length() % 8; i++) {
System.out.print("0");
}
}
}
} public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
String sp = in.nextLine();
String s = sp + "0000000";
for (int i = 0; i < s.length() / 8; i++) {
System.out.println(s.substring(i * 8, (i + 1) * 8));
}
}
} import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.nextLine();
//先求字符串长度
int length = s.length();
//按八个输出
for (int i = 0; i < length; i += 8) {
String substring;
//如果满八个
if(i+8<=length){
substring=s.substring(i,i+8);
}
//不满八个,加0
else{
substring=s.substring(i);
while(substring.length()<8){
substring+="0";
}
}
System.out.println(substring);
}
}
}