Computer Science, asked by chayanikaniyogi, 10 months ago

Write a program in Java to accept a string and replace a word with another word

Answers

Answered by pallavi7721
3

Answer:

import java. util. *;

class a

{

public static void main ()

{

Scanner sc = new Scanner(System. in);

system.out.println("enter a string ");

String str = sc.nextLine();

str = " "+str.trim();

for ( int i= str.length()-1 ; i> 0 ; i--)

{

j = str.ladtIndexOf(' ', i );

System.out.println( str.substring(j ,i+1));

i= j;

}

}

}

hope this will help you ✌✌

mark me as a brainlist

Similar questions