fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. private static List<Integer> rzuty = new ArrayList<>();
  11. private static List<String> dublety = new ArrayList<>();;
  12.  
  13.  
  14. public static void main(String[] args) {
  15. Rzucaj();
  16. String s = PrezentacjaDubletow();
  17. System.out.println(rzuty);
  18. System.out.println(s);
  19. }
  20. public static void Rzucaj() {
  21.  
  22. int ileKostek = 6;
  23. int ileScian = 6;
  24.  
  25. for (int i = 0; i < ileKostek; i++) {
  26. Random rand = new Random();
  27. int rzut = rand .nextInt(ileScian) + 1;
  28. rzuty.add(rzut);
  29. }
  30.  
  31. }
  32.  
  33.  
  34. public static String PrezentacjaDubletow() {
  35.  
  36.  
  37. Set<Integer> noDupes = new HashSet<Integer>();
  38. noDupes.addAll(rzuty); // Remove duplicates
  39.  
  40. for (Integer i : noDupes) {
  41. int wystapienia = Collections.frequency(rzuty, i);
  42. if (wystapienia > 1) {
  43. dublety.add(i + " - " + wystapienia + ";" );
  44. }
  45. }
  46.  
  47. String wynik = "";
  48. for (int i =0 ; i < dublety.size(); i++) {
  49. wynik = wynik + dublety.get(i);
  50. }
  51.  
  52.  
  53. return wynik;
  54. }
  55.  
  56.  
  57. }
  58.  
  59.  
  60.  
Success #stdin #stdout 0.08s 380160KB
stdin
Standard input is empty
stdout
[4, 2, 5, 1, 5, 6]
5 - 2;