Advertisement
Sketchware

Gerar 12 números 6 em cada TextView na TextView 3 mostra repetidos na TextView 1 e 2

Jan 16th, 2023
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. Set<Integer> uniqueNumbers1 = new HashSet<>();
  2. while (uniqueNumbers1.size() < 6) {
  3.     uniqueNumbers1.add((int)(Math.random()*10));
  4. }
  5. List<Integer> randomNumbers1 = new ArrayList<>(uniqueNumbers1);
  6.  
  7. TextView textView1 = (TextView) findViewById(R.id.textview1);
  8. textView1.setText(TextUtils.join(", ", randomNumbers1));
  9.  
  10. Set<Integer> uniqueNumbers2 = new HashSet<>();
  11. while (uniqueNumbers2.size() < 6) {
  12.     uniqueNumbers2.add((int)(Math.random()*10));
  13. }
  14. List<Integer> randomNumbers2 = new ArrayList<>(uniqueNumbers2);
  15.  
  16. TextView textView2 = (TextView) findViewById(R.id.textview2);
  17. textView2.setText(TextUtils.join(", ", randomNumbers2));
  18.  
  19. List<Integer> randomNumbers3 = new ArrayList<>(randomNumbers1);
  20. randomNumbers3.retainAll(randomNumbers2);
  21.  
  22. TextView textView3 = (TextView) findViewById(R.id.textview3);
  23. textView3.setText(TextUtils.join(", ", randomNumbers3));
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement