字符串“北京欢迎你”,替换字符为“郑州欢迎你们”,并输出打印
package com.zuoye.demo01;
/**
* 字符串“北京欢迎你”,替换字符为“郑州欢迎你们”,并输出打印
*/
public class Bhz {
public static void main(String[] args) {
String s = "北京欢迎你";
String[] str = {"北京"};
String[] str1 = {"你"};
for (int i = 0; i < str.length; i++) {
if (s.contains(str[i])) {
s = s.replace(str[i], "郑州");
s = s.replace(str1[i], "你们");
System.out.println(s);
}
}
}
}
运行结果