fork(3) 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. public class Main {
  9. public static void main (String[] args) {
  10. System.out.println("Generating name...");
  11. int length = new Scanner(System.in).nextInt();
  12. String vowels = "aeiou";
  13. String consonants = "bcdfghjklmnpqrstvwxyz";
  14. Random gen = new Random();
  15. char[][] pairs = new char[length][2];
  16. for (char[] pair : pairs) {
  17. pair[0] = vowels.charAt(gen.nextInt(vowels.length()));
  18. pair[1] = consonants.charAt(gen.nextInt(consonants.length()));
  19. }
  20. System.out.println("Generated!");
  21. System.out.print("The name is: ");
  22. StringBuilder name = new StringBuilder();
  23. for (char[] pair : pairs) {
  24. if (gen.nextBoolean()) {
  25. name.append(pair[0]);
  26. name.append(pair[1]);
  27. } else {
  28. name.append(pair[1]);
  29. name.append(pair[0]);
  30. }
  31. }
  32. if (gen.nextBoolean()) {
  33. if (vowels.indexOf(name.charAt(name.length() - 1)) != -1) {
  34. name.append(consonants.charAt(gen.nextInt(consonants.length())));
  35. } else {
  36. name.append(vowels.charAt(gen.nextInt(vowels.length())));
  37. }
  38. }
  39. System.out.println(toDisplayCase(name.toString()));
  40. }
  41.  
  42. public static String toDisplayCase(String s) {
  43. final String ACTIONABLE_DELIMITERS = " '-/";
  44. StringBuilder sb = new StringBuilder();
  45. boolean capNext = true;
  46. for (char c : s.toCharArray()) {
  47. c = (capNext)
  48. ? Character.toUpperCase(c)
  49. : Character.toLowerCase(c);
  50. sb.append(c);
  51. capNext = (ACTIONABLE_DELIMITERS.indexOf((int) c) >= 0);
  52. }
  53. return sb.toString();
  54. }
  55. }
Success #stdin #stdout 0.14s 321088KB
stdin
4
stdout
Generating name...
Generated!
The name is: Effawided