Question 1049: Remove a specific character from a string

Source: Internet
Author: User
Description:

The input string S and character C must be removed from all the C characters in S and output results.

Input:

There are multiple groups of test data, with each group of input strings S and character C.

Output:

For each group of inputs, the output results after the C characters are removed.

Sample input:
healloa
Sample output:
hello
Source:
A trial of computer research vitality of Harbin Institute of Technology in 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: 104926     User: 0000H27     Language: Java28     Result: Accepted29     Time:80 ms30     Memory:15416 kb31 ****************************************************************/

 

Question 1049: Remove a specific character from a string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.