Put spaces between words starting with capital letters | Java program to put spaces between words starting with capital letters . ; Function to amend the sentence ; Traverse the string ; Convert to lowercase if its an uppercase character ; Print space before it if its an uppercase character ; Print the character ; if lowercase character then just print ; Driver Code
import java . util . * ; import java . lang . * ; import java . io . * ; class AddSpaceinSentence { public static void amendSentence ( String sstr ) { char [ ] str = sstr . toCharArray ( ) ; for ( int i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) { str [ i ] = ( char ) ( str [ i ] + 32 ) ; if ( i != 0 ) System . out . print ( " ▁ " ) ; System . out . print ( str [ i ] ) ; } else System . out . print ( str [ i ] ) ; } } public static void main ( String [ ] args ) { String str = " BruceWayneIsBatman " ; amendSentence ( str ) ; } }