Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class GeneradorDeLetra {
  4. public static final int LETRA_A = 97;
  5. public static final int LETRA_z = 122;
  6. public final static Random generador = new Random();
  7.  
  8. public static char genLetra(){
  9. return (char)genNroAsCiiLetra();
  10. }
  11.  
  12. private static int genNroAsCiiLetra(){
  13. return generador.nextInt(LETRA_z - LETRA_A + 1) + LETRA_A;
  14. }
  15. }
  16.  
  17. import java.util.*;
  18. import java.util.function.Function;
  19. import java.util.stream.Stream;
  20.  
  21. import static java.util.stream.Collectors.toList;
  22.  
  23. public class DemoClubDeVideo {
  24. public static void main(String[] args)throws UnknownHostException {
  25. Optional<String> palabra =
  26. Stream.generate(GeneradorDeLetra::genLetra)
  27. .limit(10)
  28. .map(String::valueOf)
  29. .reduce(String::concat);
  30.  
  31. if(palabra.get().indexOf('z') != -1) {
  32. System.out.println("palabra " + palabra.get()+" tiene letra(z)");
  33. }else{
  34. System.out.println("palabra " + palabra.get()+ " no tiene letra(z)");
  35. }
  36.  
  37. }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement