fork download
  1. import java.util.stream.Collectors;
  2. import java.util.Random;
  3. import java.util.SortedSet;
  4. import java.util.TreeSet;
  5.  
  6. class Teste {
  7. private static final Random RND = new Random();
  8.  
  9. private static String comZero(int x) {
  10. return (x < 10 ? "0" : "") + x;
  11. }
  12.  
  13. private static String sortear() {
  14. SortedSet<Integer> numberset = new TreeSet<>();
  15. while (numberset.size() < 6) {
  16. numberset.add((RND.nextInt(60) + 1));
  17. }
  18. return numberset.stream().map(Teste::comZero).collect(Collectors.toList()).toString();
  19. }
  20.  
  21. public static void main(String[] args) {
  22. System.out.println(sortear());
  23. }
  24. }
Success #stdin #stdout 0.19s 2184192KB
stdin
Standard input is empty
stdout
[01, 28, 34, 46, 48, 49]