fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.Scanner;
  5.  
  6. public class Main
  7. {
  8. public static void main(String[] args)
  9. {
  10. Scanner in = new Scanner(System.in);
  11. String s = in.nextLine();
  12. s = s.replaceAll(" +", " ");
  13. if(s.charAt(0) == ' ')
  14. {
  15. s = s.substring(1, s.length());
  16. }
  17. if(s.charAt(s.length()-1) == ' ')
  18. {
  19. s = s.substring(0, s.length()-1);
  20. }
  21. System.out.print(s);
  22. }
  23. }
Success #stdin #stdout 0.06s 4386816KB
stdin
 Mr    Charlie    Chaplin   
stdout
Mr Charlie Chaplin