Advertisement
Sketchware

Criar 15 números textView1 e textView2 e mostra no textView3 os repetidos no textView1 e textView2

Jan 16th, 2023
102
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() < 16) {
  3.     uniqueNumbers1.add((int)(Math.random()*26));
  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() < 16) {
  12.     uniqueNumbers2.add((int)(Math.random()*26));
  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