Computer Science, asked by NISHAThameeda6836, 9 months ago

Write a program to accept a sample string and replace the word blue with red .

Answers

Answered by nitarawat14
6

Answer:

Heya user ,

Here is your answer !!

______________________

import java.util.*;

public class Words

{

public static void main ( String args [] )

{

Scanner in = new Scanner ( System.in ) ;

System.out.print ( " Enter a sentence : " ) ;

String S = in.nextLine() ;

S = S.trim();

EXPLANATION :

☆ S is the actual string .

☆ Now , we trim the string so that all the extra spaces at the beginning and at the end are removed .

☆ The ' for ' loop count the number of blank spaces in the string .

☆ The no. of blank spaces is stored in the variable k .

Similar questions