题解 | #替换空格#
替换空格
https://www.nowcoder.com/practice/0e26e5551f2b489b9f58bc83aa4b6c68
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return string字符串 */ public String replaceSpace (String s) { // write code here //方法一:定义一个char数组用于将字符s转为单个字符分别存放 //对char数组进行遍历,如果字符有空格则追加"%20" String ss = new String(); char[] str = s.toCharArray(); for (char i : str) { if (i == ' ') { i = '%'; ss = ss + i; ss = ss + "20"; } else { ss = ss + i; } } return ss; } f }#小白的技术进阶日记#