Thursday, July 15, 2021

13. Write a java program to replace spaces with underscores.

public class Main {

      public static void main(String[] args) {

          String name = "Berry is my brother and he is a nice brother";

          System.out.println(name.replace(" ", "_"));

     }

}


NOTE:

The output of this program is Berry_is_my_brother_and_he_is_a_nice_brother. By using .replace(); all the spaces in the String will be changed to underscores in the output. 

No comments:

Post a Comment