//输入一个字符串,长度大于8截取8位,剩下的换行补0,不够8位的补0
//例如:
输入:
abc
输出:
abc00000
输入:
12345678123
输出:
12345678
12300000
Scanner sc=new Scanner(System.in);
String xx=sc.next();
StringBuilder abc=new StringBuilder(xx);
if(abc.length()<=8)
{
int n=8-abc.length();//计算需要补位多少个0
String[] n1=new String[n];
for (int i = 0; i < n1.length; i++)
{
n1[i]="0"; //将补位的0都放入数组中
abc.append(n1[i]);//将补位数组追加到StringBuilder
}
}
else
{
//先补0后换行
int n=8-(abc.length()%8);
String[] n1=new String[n];
for (int i = 0; i < n1.length; i++)
{
n1[i]="0";
abc.append(n1[i]);
}
for (int i = 0; i < abc.length(); i++)
{
if((i)%9==0)//每隔8个字符串长度换行,insert方法的offset从当前索引添加,故+1
{
abc.insert(i, "\n");
}
}
}
System.out.println(abc);
}