fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12.  
  13. String input = "abcdefghijkl" ;
  14.  
  15. System.out.println( "abcdefghijkl".substring(0 , 10 ) ) ;
  16.  
  17. String output =
  18. ( input.length() > 10 ) // If too long…
  19. ?
  20. input
  21. .substring( 0 , 10 - 1 ) // Take just the first part, adjusting by 1 for zero-based index counting, and adjusting by 1 again to replace that last character with an ellipsis.
  22. .concat( "…" ) // Add the ellipsis character.
  23. : // Or, if not too long…
  24. input // Just return original string.
  25. ;
  26.  
  27. System.out.println( "output: " + output ) ;
  28. }
  29. }
Success #stdin #stdout 0.09s 35764KB
stdin
Standard input is empty
stdout
abcdefghij
output: abcdefghi…