Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. //: interfaces/RandomWords.java
  2. // Реализация интерфейса для выполнения требований метода
  3. import java.nio.*;
  4. import java.util.*;
  5.  
  6. public class RandomWords implements Readable {
  7. private static Random rand = new Random(47);
  8. private static final char[] capitals =
  9. "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
  10. private static final char[] lowers =
  11. "abcdefghijklmnopqrstuvwxyz".toCharArray();
  12. private static final char[] vowels =
  13. "aeiou".toCharArray();
  14. private int count;
  15. public RandomWords(int count) { this.count = count; }
  16. public int read(CharBuffer cb) {
  17. if(count-- == 0)
  18. return -1; // Признак конца входных данных
  19. cb.append(capitals[rand.nextInt(capitals.length)]);
  20. for(int i = 0; i < 4; i++) {
  21. cb.append(vowels[rand.nextInt(vowels.length)]);
  22. cb.append(lowers[rand.nextInt(lowers.length)]);
  23. }
  24. cb.append(" ");
  25. return 10; // Количество присоединенных символов
  26. }
  27. public static void main(String[] args) {
  28. Scanner s = new Scanner(new RandomWords(10));
  29. while(s.hasNext())
  30. System.out.println(s.next());
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement