当前位置:网站首页>HJ4 字符串分隔
HJ4 字符串分隔
2022-04-22 01:47:00 【敏敏程序媛】
描述
•输入一个字符串,请按长度为8拆分每个输入字符串并进行输出;
•长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。
输入描述:
连续输入字符串(每个字符串长度小于等于100)
输出描述:
依次输出所有分割后的长度为8的新字符串
示例1
输入:abc
输出:abc00000
import java.util.Scanner;
/**
*@ Author:向敏
*@ date:2022-04-08
*/
public class Main
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
StringBuilder builder = new StringBuilder(256);
while(scanner.hasNextLine())
{
builder.setLength(0);
String input = scanner.nextLine();
stringSpring(builder,input);
System.out.print(builder);
}
scanner.close();
}
private static void stringSpring(StringBuilder builder,String str)
{
if (str == null || str.length() < 1)
{
return;
}
int pos = 0;
while ((pos += 8) < str.length())
{
builder.append(str.substring(pos-8,pos)).append("\n");
}
//如果str.length() < pos,说明最后的不足8个字符或者刚好8个
if (str.length() <= pos)
{
builder.append(str.substring(pos - 8,str.length()));
for (int i = str.length(); i < pos; i++)
{
builder.append(0);
}
builder.append("\n");
}
}
}
版权声明
本文为[敏敏程序媛]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_28841515/article/details/124244800
边栏推荐
- PHY6222国产低功耗多协议蓝牙SoC芯片
- In depth understanding Construction mode of thread synchronization in. Net (1) user mode construction
- Code source daily question div1 (601-607)
- mysql 查询 上个月20号到 当前系统月份(本月)19号之间的数据
- 作为一名软件测试从业人员,你有弄明白你的发展方向吗?
- Appium移动端自动化测试--搭建模拟器和真机环境一
- net easy
- 阿里专家原创,自学编程找工作
- Code source daily question div1 (201-207)
- 面试链表题
猜你喜欢

stack和queue

(一)postman遇到报错:There was an error connecting to XXXX

谷粒商城-学习笔记-基础篇-商品服务1(P45-P58)

Alibaba Android development specification, senior programmer interview questions

C# UserControl造成内存泄漏

作为一名软件测试从业人员,你有弄明白你的发展方向吗?

VMware虚拟机安装详细教程网络NAT、网桥配置

Programmers' black technology | daily anecdotes

Isla obscura deep sea biological series NFT market platform
Ali Daniel collates, Android interview multiple-choice questions
随机推荐
Thief, the latest Android interview collection
C language curriculum design
Fundamentals lecture 30 Lecture 9 geometric application of univariate function integration
I really envy those who don't need to send a circle of friends
[several common buttons in swing]
[Lua program to control the mobile phone to chat] - it is used to keep the number. You can put down your hand for automatic chat and keep the number
Appium mobile terminal automated testing -- building a simulator and real machine environment
Station B charging | charging more than 1500 a week, Yinfa up is the new dark horse of station B?
Penetration test of Mr robot target
Crawler learning - data storage after obtaining data (writing and reading of CSV & Excel)
[编程题]有趣的数字
代码源每日一题 div1(101-109)
MSF series - Eternal Blue vulnerability
互联网使用代理IP有哪些作用?
Zabbix深度监控:多款开源工具构建企业监控新架构
The idea window cannot be found in multi screen mode
mysql 查询 上个月20号到 当前系统月份(本月)19号之间的数据
What do you know about the ADB order in 2022? A 2000 word detailed ADB command is coming
How to make color ribbon font? AE tutorial teaches you
oracle安装server端