Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<Set<Integer>> uniqueNumbersList = new ArrayList<>();
- List<List<Integer>> randomNumbersList = new ArrayList<>();
- List<TextView> textViewList = new ArrayList<>();
- for (int i = 0; i < 4; i++) {
- Set<Integer> uniqueNumbers = new HashSet<>();
- while (uniqueNumbers.size() < 25) {
- uniqueNumbers.add((int)(Math.random()*26) + 1);
- }
- uniqueNumbersList.add(uniqueNumbers);
- List<Integer> randomNumbers = new ArrayList<>(uniqueNumbers);
- randomNumbersList.add(randomNumbers);
- TextView textView = (TextView) findViewById(getResources().getIdentifier("textview" + (i + 1), "id", getPackageName()));
- textView.setText(TextUtils.join(", ", randomNumbers));
- textViewList.add(textView);
- }
- Set<Integer> repeatedNumbers = new HashSet<>(randomNumbersList.get(0));
- for (int i = 1; i < 4; i++) {
- repeatedNumbers.retainAll(randomNumbersList.get(i));
- }
- for (Integer num : repeatedNumbers) {
- for (int i = 0; i < 4; i++) {
- int start = textViewList.get(i).getText().toString().indexOf(num.toString());
- int end = start + num.toString().length();
- Spannable spannable = new SpannableString(textViewList.get(i).getText());
- spannable.setSpan(new ForegroundColorSpan(Color.RED), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- textViewList.get(i).setText(spannable);
- }
- }
- TextView textView5 = (TextView) findViewById(R.id.textview5);
- String repeatedNumber = "Números repetidos: " + repeatedNumbers.size();
- textView5.setText(repeatedNumber);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement