Program to replace word.
Write a program to replace any word of a entered string with another word.
SOURCE CODE
import java.io.*;
import java.util.*;
public class Replacing_Words
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter a String :");
String str=sc.nextLine();
System.out.print("Enter a word from the same string you have entered :");
String s1=sc.next();
System.out.print("Enter another word :");
String s2=sc.next();
System.out.println("\nAfter replacing all "+s1+" with "+s2+" OUTPUT will be");
System.out.println(str.replace(s1,s2));
}
}
OUTPUT
If you have any question then leave a comment below I will do my best to answer that question.
Comments
Post a Comment