148. JAVA Program to delete particular word from the given line of text.
How does this program work?
- This program is used to delete particular word from the given line of text using java.
Here is the code
//To delete particular word from the given line of text
import java.util.Scanner;public class word
{
public static void main(String args[] )
{
String str, word;
System.out.print("Enter a String : \n");
Scanner obj = new Scanner(System.in );
str = obj.nextLine();
System.out.print("Enter a Word to be Delete from the String : \n");
word = obj.nextLine();
System.out.print("Deleting all '" + word + "' from '" + str + "'\n");
str = str.replaceAll(word, "");
System.out.print("\nNow the String is :\n" );
System.out.print(str);
}
}