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. String test = "dots: ";
  13. System.out.println(test+getDots(40));
  14. System.out.println(test+getStrWithDots(40,"test testing"));
  15.  
  16. }
  17.  
  18. public static String getDots(int num){
  19. StringBuilder sb = new StringBuilder();
  20. for(int i = 0; i<num;i++){
  21. sb.append(".");
  22. }
  23. return sb.toString();
  24. }
  25.  
  26. public static String getStrWithDots(int dots, String str){
  27.  
  28. int strSize = str.length();
  29. int dotsRemained = 0;
  30. StringBuilder sb = new StringBuilder();
  31. if((strSize/**2*/)>dots)
  32. dotsRemained =0;
  33. else
  34. dotsRemained = dots-(strSize/**2*/);
  35.  
  36. for(int i = 0; i<dotsRemained;i++){
  37. if(i==(dotsRemained/2)){
  38. sb.append(str);
  39. }
  40. sb.append(".");
  41.  
  42. }
  43. return sb.toString();
  44. }
  45.  
  46.  
  47. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
dots: ........................................
dots: ..............test testing..............