码迷,mamicode.com
首页 > 其他好文 > 详细

eg_5

时间:2017-09-09 20:22:28      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:demo   字符串   www   pen   dem   第一个字符   line   append   next   

问题描述:输入两个字符串,从第一字符串中删除第二个字符串中所有的字符。

例如,输入”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.

eg_5

标签:demo   字符串   www   pen   dem   第一个字符   line   append   next   

原文地址:http://www.cnblogs.com/bosongokay/p/7499102.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!