Write a java program to convert a string in negative string

Given a string input, write a program to replace every appearance of the word “is” by “is not”.

If the word “is” is immediately preceded or followed by a letter no change should be made to the string.

Input and Output Format:

Input consists of a String.

The output consists of a String.

Sample Input 1:

This is just a misconception

Sample Output 1:

This is not just a misconception

Sample Input 2:

Today is misty

Sample Output 2:

Today is not misty

Convert a string into the negative string in Java.

public class Sort
{
  public static void main(String [] args)
  {
    Scanner sc= new Scanner(System.in);
  String str=sc.nextLine();
    
    String n=str.replaceAll(" is ", " is not ");
  System.out.println(n);
  
    
    }
}

Add a Comment

Your email address will not be published. Required fields are marked *

three × 5 =