How to insert spaces between words that start with capital in a string with Java

1 Answer

0 votes
public class MyClass {
    static String insert_spaces(String s) { 
        for (int i = 1, j = 0; i < s.length(); i++) {
             if (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z') { 
                 s = s.substring(0, i) + " " + s.substring(i, s.length());
                 i++;
             }
        }
        return s;
    } 
  
    public static void main(String args[]) {
        String s = "PythonJavaPascalC#C++F#";
  
        s = insert_spaces(s);
          
        System.out.println(s);
    }
}
  
  
    
    
/*
    
Python Java Pascal C# C++ F#
    
*/

 



answered Jan 15, 2020 by avibootz
edited Jan 15, 2020 by avibootz
...