Question is in the attachment
Answers
The given problem is solved using language - Java.
import java.util.Scanner;
public class Brainly{
public static void main(String s[]){
Scanner sc=new Scanner(System.in);
String sentence, word1, word2;
System.out.print("Enter a sentence: ");
sentence=sc.nextLine();
System.out.print("Enter a word: ");
word1=sc.next();
System.out.print("Enter another word: ");
word2=sc.next();
sc.close();
System.out.println("Original Sentence: "+sentence);
sentence=sentence.replace(word1,word2);
System.out.println("Modified Sentence: "+sentence);
}
}
- In java, replace() method replaces a string with another string. Using this method, the problem is solved.
See the attachment for output.
The given problem is solved using language - Java.
import java.util.Scanner;
public class Brainly{
public static void main(String s[]){
Scanner sc=new Scanner(System.in);
String sentence, word1, word2;
System.out.print("Enter a sentence: ");
sentence=sc.nextLine();
System.out.print("Enter a word: ");
word1=sc.next();
System.out.print("Enter another word: ");
word2=sc.next();
sc.close();
System.out.println("Original Sentence: "+sentence);
sentence=sentence.replace(word1,word2);
System.out.println("Modified Sentence: "+sentence);
}
}
\textsf{\large{\underline{Explanation}:}}
Explanation
:
In java, replace() method replaces a string with another string. Using this method, the problem is solved.
See the attachment for output.