gpt4 book ai didi

java - 根据字符数向字符串添加新行

转载 作者:太空宇宙 更新时间:2023-11-04 12:45:58 25 4
gpt4 key购买 nike

所以我试图对一行文本施加限制并告诉它何时开始新行。因此,如果输入的文本大于 12,则会创建一个新行并继续。

到目前为止,我已经了解了 if 语句的开头,然后我就迷路了。我已经查看了从名为 inputName 的字符串分支的方法,但找不到我正在搜索的内容。

if (inputName.length() > 12) {
inputName.
}

最佳答案

 String inputName="1234567890121234567890121234567890121234567890121234567890";
while (inputName.length() > 12) {
System.out.print(inputName.substring(0,12)+System.getProperty("line.separator"));
inputName = inputName.substring(12);
}
System.out.print(inputName+System.getProperty("line.separator"));

关于java - 根据字符数向字符串添加新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36321909/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com