Write a java program to remove a character from a string.

Write a program to input a String and a character, and remove that character from the given String. Print the final string.

Input and Output Format:

Input consists of a string and a character.

The output consists of a string(the character cleaned string).

Refer sample output for formatting specifications.

Sample Input :

elephant

e

Sample Output:

Lphant

Remove a character from a string in Java.

import java.util.Scanner;

public class Main {
public static void main(String[]args){
                                Scanner sc=new Scanner(System.in);
                                String name=sc.nextLine();
                                String ch=sc.next();


                                System.out.println(name.replace(ch,""));



                }

        
}

Add a Comment

Your email address will not be published. Required fields are marked *

eighteen + six =