fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.concurrent.ThreadLocalRandom;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. private static final String chars = "abcdefghijklmnopqrstuvwxyz";
  9. private static final String CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  10. private static final String NUMS = "1234567890";
  11. private static final String SPEC = "@#$%^&+=";
  12.  
  13. public static void main(String[] args) {
  14. StringBuffer buf = new StringBuffer(8);
  15. appendChars(2, chars, buf);
  16. appendChars(2, CHARS, buf);
  17. appendChars(2, NUMS, buf);
  18. appendChars(2, SPEC, buf);
  19.  
  20. System.out.println(buf);
  21. }
  22.  
  23. private static void appendChars(int n, String src, StringBuffer buf) {
  24. ThreadLocalRandom r = ThreadLocalRandom.current();
  25. while (--n >= 0) buf.append(src.charAt(r.nextInt(src.length())));
  26. }
  27. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
gwCK42+@