豆包打卡第六天

78 阅读1分钟

给定一个字符串ss,编写一个函数,将字符串中的小写字母a替换为"%100",并返回替换后的字符串。

例如,对于字符串"abcdwa",所有a字符会被替换为"%100",最终结果为%100bcdw%100"

代码:

public class Main { public static String solution(String s) { // 使用 String 的 replace 方法将所有小写字母 'a' 替换为 "%100" return s.replace("a", "%100"); }

public static void main(String[] args) {
    System.out.println(solution("abcdwa").equals("%100bcdw%100"));
    System.out.println(solution("banana").equals("b%100n%100n%100"));
    System.out.println(solution("apple").equals("%100pple"));
}

}