Skip to content

Instantly share code, notes, and snippets.

@Ram-1234
Created April 30, 2021 16:57
Show Gist options
  • Save Ram-1234/08f929d99f63c344a5cafc16c3518ade to your computer and use it in GitHub Desktop.
Save Ram-1234/08f929d99f63c344a5cafc16c3518ade to your computer and use it in GitHub Desktop.
remove a substring from given string
Example-1
input;-
I am a very good engineer
very
output:-
I am a good engineer
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
String name=sc.nextLine();
String key=sc.nextLine();
//System.out.println(key);
String result=name.replace(key,"");
result=result.replaceAll(" +"," ");
System.out.println(result.trim());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment