Print all the non | Java program to print all the non - repeating words from the two given sentences ; Function to print all the non - repeating words from the two given sentences ; Concatenate the two Strings into one ; Iterating over the whole concatenated String ; Searching for the word in A . If while searching , we reach the end of the String , then the word is not present in the String ; Initialise word for the next iteration ; Driver code
class GFG { static void removeRepeating ( String s1 , String s2 ) { String s3 = s1 + " ▁ " + s2 + " ▁ " ; String words = " " ; int i = 0 ; for ( char x : s3 . toCharArray ( ) ) { if ( x == ' ▁ ' ) { if ( ! s1 . contains ( words ) || ! s2 . contains ( words ) ) System . out . print ( words ) ; words = " ▁ " ; } else { words = words + x ; } } } public static void main ( String [ ] args ) { String s1 = " I ▁ have ▁ go ▁ a ▁ pen " ; String s2 = " I ▁ want ▁ to ▁ go ▁ park " ; removeRepeating ( s1 , s2 ) ; } }