fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.Random;
  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. java.util.Scanner scanner = new java.util.Scanner(System.in);
  14.  
  15. int letterNum = 6;
  16. Random rn = new Random();
  17. char letter = (char) (rn.nextInt(26) + 'a');
  18. boolean shouldCons = true;
  19. char[] vowels = { 'a', 'e', 'i', 'o', 'u' };
  20.  
  21. while (true)
  22. {
  23. //Ask user for word's length and store it
  24. System.out.println();
  25. System.out.print("Please enter the length of the word in letters: ");
  26. try{
  27. letterNum = scanner.nextInt();
  28. }catch(Exception e){
  29. break;
  30. }
  31.  
  32. for (int i = 0; i < letterNum; i++, shouldCons^=true)
  33. {
  34. if(shouldCons) {
  35. letter = (char) (rn.nextInt(26) + 'a');
  36. while (letter == 'a' || letter == 'u' || letter == 'i' || letter == 'e' || letter == 'o')
  37. {
  38. letter = (char) (rn.nextInt(26) + 'a');
  39. }
  40. }
  41. else letter = vowels[(int)(Math.random() * 5)];
  42.  
  43. System.out.print(letter);
  44. }
  45. }
  46. }
  47. }
Success #stdin #stdout 0.05s 711680KB
stdin
10
stdout
Please enter the length of the word in letters: kayegedozo
Please enter the length of the word in letters: