ch1_6_2求解删除公共字符问题

输入两个字符串,从第一字符串中删除第二个字符串中所有的字符。例如,输入”They are students.”和”aeiou”,则删除之后的第一个字符串变成”Thy r stdnts.”

输入描述:

每个测试输入包含2个字符串

输出描述:

输出删除后的字符串

示例1

输入

They are students. aeiou

输出

Thy r stdnts.
import java.util.Scanner;

public class ch1_6_2求解删除公共字符问题 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		String s=in.nextLine();
		String t=in.nextLine();
		for(int i=0;i<t.length();i++) {
			if(s.contains(t.charAt(i)+"")) {
				s=s.replaceAll(t.charAt(i)+"", "");
			}
		}
		System.out.println(s);
		
	}

}

猜你喜欢

转载自blog.csdn.net/Liuyaoyun/article/details/88085043
今日推荐