Java Program to replace the spaces of a string with a specific character

Java Program to replace the spaces of a string with a specific character

Example:

Input:  str = "Java is the Programming Language";
Output: Java\is\the\Programming\Language

Approach

Java


public class ReplaceSpace {
    public static void main(String[] args) {
        String str = "Java is the Programming Language";
        char sChar = '\\';
        str = str.replace(' ', sChar);
        System.out.println(str);
    }
}


No comments:

Post a Comment