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. // your code goes here
  13. String expected1Space = "Home: email@gmail.com"; // 1 space after colon
  14. String expected7Spaces = "Home: email@email.com"; // (7 spaces after the colon)
  15. String email = "email@gmail.com"; // address is 15 long
  16. String padded5AddedSpaces = " "; // plus 5 equals padding 20 = minimum space required is 20
  17.  
  18. String format1 = String.format("Home: %s", email);
  19. System.out.println("no padding:\n\t" + format1);
  20. assert expected1Space == format1;
  21.  
  22. String format7 = String.format("Home:%7s%s", "", email);
  23. System.out.println("effective spacing:\n\t" + format7);
  24. assert expected7Spaces == format7;
  25.  
  26. String format5 = String.format("Home:%20s", email);
  27. System.out.println("real left padding to 20:\n\t" + format5);
  28. assert "Home:" + padded5AddedSpaces + email == format5;
  29. }
  30. }
Success #stdin #stdout 0.14s 36392KB
stdin
Standard input is empty
stdout
no padding:
	Home: email@gmail.com
effective spacing:
	Home:       email@gmail.com
real left padding to 20:
	Home:     email@gmail.com