Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. Scanner scan= new Scanner(System.in);
  2. int val = scan.nextInt();
  3. String b[]= {"a","e","i","o","u"};
  4.  
  5. Set<String> uniq= new HashSet<>();
  6. ArrayList<String> arr= new ArrayList<>();
  7.  
  8. for(int i=1;i<=val;i++) {
  9. if(uniq.isEmpty()) {
  10. for(int j=0;j<b.length;j++) {
  11. uniq.add(b[j]);
  12. }
  13. }
  14. else {
  15. List<String> copy= new ArrayList<String>(uniq);
  16. for(int j=0;j<b.length;j++) {
  17.  
  18. for(String object : copy) {
  19. String element = (String) object;
  20. uniq.add(element+b[j]);
  21. }
  22.  
  23.  
  24. }
  25. }
  26. }
  27. System.out.println("Set Size= "+uniq.size());
  28. Iterator<String> ite= uniq.iterator();
  29. while (ite.hasNext()) {
  30. String v=ite.next();
  31. int len= v.length();
  32. if(len==val) {
  33. arr.add(v);
  34. }
  35. }
  36. Collections.sort(arr);;
  37. for(int l=0;l<arr.size();l++) {
  38. System.out.print(arr.get(l)+" ");
  39. }
  40. System.out.println("");
  41. System.out.println(arr.size());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement