问题描述:输入两个字符串,从第一字符串中删除第二个字符串中所有的字符。
例如,输入”They are students.”和”aeiou”,则删除之后的第一个字符串变成”Thy r stdnts.”
Demo_1:
package com.studentmanager.www; import java.util.Scanner; public class Test6 { public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("请输入两行字符串-------"); String s1 = input.nextLine(); String s2 = input.nextLine(); StringBuffer sb = new StringBuffer(); for(int i=0;i<s1.length();i++){ if(!s2.contains(s1.charAt(i)+"") ){ sb.append(s1.charAt(i)); } } System.out.println(s2.contains(" ")); System.out.println(sb); } } // They are students. // aeiou
运行结果:
They are students.
aeiou
false
Thy r stdnts.
时间: 2024-12-25 00:40:16