Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Set<Integer> uniqueNumbers1 = new HashSet<>();
- while (uniqueNumbers1.size() < 50) {
- uniqueNumbers1.add((int)(Math.random()*101));
- }
- List<Integer> randomNumbers1 = new ArrayList<>(uniqueNumbers1);
- TextView textView1 = (TextView) findViewById(R.id.textview1);
- textView1.setText(TextUtils.join(", ", randomNumbers1));
- Set<Integer> uniqueNumbers2 = new HashSet<>();
- while (uniqueNumbers2.size() < 50) {
- int randomNum = (int)(Math.random()*101);
- if(!randomNumbers1.contains(randomNum))
- uniqueNumbers2.add(randomNum);
- }
- List<Integer> randomNumbers2 = new ArrayList<>(uniqueNumbers2);
- TextView textView2 = (TextView) findViewById(R.id.textview2);
- textView2.setText(TextUtils.join(", ", randomNumbers2));
- List<Integer> randomNumbers3 = new ArrayList<>(randomNumbers1);
- randomNumbers3.retainAll(randomNumbers2);
- for (Integer num : randomNumbers3) {
- int start1 = textView1.getText().toString().indexOf(num.toString());
- int end1 = start1 + num.toString().length();
- int start2 = textView2.getText().toString().indexOf(num.toString());
- int end2 = start2 + num.toString().length();
- Spannable spannable1 = new SpannableString(textView1.getText());
- spannable1.setSpan(new ForegroundColorSpan(Color.RED), start1, end1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- textView1.setText(spannable1);
- Spannable spannable2 = new SpannableString(textView2.getText());
- spannable2.setSpan(new ForegroundColorSpan(Color.RED), start2, end2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- textView2.setText(spannable2);
- }
- TextView textView3 = (TextView) findViewById(R.id.textview3);
- Set<Integer> uniqueNumbers3 = new HashSet<>(); while (uniqueNumbers3.size() < 50) { uniqueNumbers3.add((int)(Math.random()*101)); } List<Integer> randomNumbers4 = new ArrayList<>(uniqueNumbers3);
- TextView textView4 = (TextView) findViewById(R.id.textview4); textView4.setText(TextUtils.join(", ", randomNumbers4));
- String repeatedNumber = "Números repetidos: " + randomNumbers3.size();
- textView3.setText(repeatedNumber);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement