gpt4 book ai didi

java - 如何检测字符串中的空格?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:15:55 26 4
gpt4 key购买 nike

               String  test="This is a simple text"

是否可以通过查看空格来检测空格并写入下一行?我的意思是有这样的控制台输出:

                      This is a simple text
++++ ++ + ++++++ ++++

最佳答案

public class StringPlus {

public static void main(String[] args) {
String test="This is a simple text";
for(char c: test.toCharArray()){
System.out.print((c == ' ') ? " ":"+");
}
}
}

关于java - 如何检测字符串中的空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20576758/

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