题目1049:字符串去特定字符

题目描述:

输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果。

输入:

测试数据有多组,每组输入字符串s和字符c。

输出:

对于每组输入,输出去除c字符后的结果。

样例输入:
heallo
a
样例输出:
hello
来源:
2009年哈尔滨工业大学计算机研究生机试真题
 1 import java.math.BigInteger;
 2 import java.util.Arrays;
 3 import java.util.Scanner;
 4  
 5 public class Main{
 6     public static void main(String[]args){
 7     Scanner in=new Scanner(System.in);
 8     while(in.hasNext()){
 9        String s=in.nextLine();
10        String t=in.nextLine();
11        char c=t.charAt(0);
12        char[]s2c=s.toCharArray();
13        int len=s2c.length;
14        s="";
15        for(int i=0;i<len;i++){
16            if(s2c[i]==c) continue;
17            s+=s2c[i];
18        }
19         System.out.println(s);
20     }
21     }
22  }
23  
24 /**************************************************************
25     Problem: 1049
26     User: 0000H
27     Language: Java
28     Result: Accepted
29     Time:80 ms
30     Memory:15416 kb
31 ****************************************************************/
原文地址:https://www.cnblogs.com/qq1029579233/p/4485541.html