Remove character

 

For a given a string(str) and a character X, write a function to remove all the occurrences of X from the given string.

Sample Input 1:
aabccbaa
a
Sample Output 1:
bccb
public class Solution {

	public static String removeAllOccurrencesOfChar(String str, char ch) {
	
        
        int l=str.length();
        String s="";
        for(int i=0;i<l;i++)
            
        {
            char c = str.charAt(i);
            if(ch!=c)
            {
                s=s+c;
            }
        }
        return s;
	}

}

Comments

Popular posts from this blog

Minimum Length Word

Check Number Sequence