Write a Java program to replace a string "python" with "java" and "java" with "python" in a given string.

 /*

Write a Java program to replace a string "python" with "java" and "java" with "python" in a given string.

Expected Output:

Input the string:

python is more propular than java

New string:

java is more propular than python

*/

import java.util.*;

class Seventeen 

{

    public static void main(String arg[])

    {        

        Scanner in = new Scanner(System.in);

        System.out.print("\n Enter any String for java or python : ");

        String str = in.nextLine();

        str = str.replaceAll("java", "py_thon");

        str = str.replaceAll("python", "java");

        str = str.replaceAll("py_thon", "python");

        System.out.println("\n New String : " + str);

    }

}

More Information on our channel Programmer Community

please like , share and subscribe to get notifications of new videos....

To understand this program video will coming soon on our you tube channel



Comments

Popular posts from this blog

Design and Develop a java program to read marks of a student and print the total and average of marks using scanner class.

Write a Java program to convert seconds to hour, minute and seconds.

Write a Java program to print the ascii value of a given character.