Computer Science, asked by SƬᏗᏒᏇᏗƦƦᎥᎧƦ, 1 month ago

Question is in the attachment​

Attachments:

Answers

Answered by anindyaadhikari13
19

\textsf{\large{\underline{Solution}:}}

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}:}}

  • In java, replace() method replaces a string with another string. Using this method, the problem is solved.

See the attachment for output.

Attachments:

anindyaadhikari13: Thanks for the brainliest :)
Answered by Anonymous
0

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.

Similar questions